Giter VIP home page Giter VIP logo

leetcode_js's Introduction

技巧

&、^、| 、 >> 几种二进制运算

1、 ^ 无进制 按位 相加 (有1才有1)
2、 | 无进制 按位 相减 (不同才有1)
3、 & (同1才1)
4、 >> 右移运算符 (例如:  a >> 1 相当于 a / 2 ,但是 二进制运算会比 / 快)

获取当前数二进制中,提取最右侧的1

eor & (~eor + 1);

对数器

使用一个暴力解用于保证一定能解决此问题,然后随机生成样本,比较当前认为最优解,和暴力解的计算结果,如果随机生成 500000次都是一样的,大概率可以认为 最优解是正确的

计算 length mid

mid = L + ((R - L) >> 1);
不建议通过 (L + R) / 2 ,因为容易溢出,没有相加前两个数较大接近溢出,那么一相加绝对溢出

master公式

image

leetcode_js's People

Contributors

astrid-xin-li avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.