Git Product home page Git Product logo

algorithm's Introduction

algorithm

ps:目前单元测试写得并不规范,因为有些结果太难构造了,没有使用断言,所以仅用与调试

排序复杂度

数学

  • 一个数和它本身做异或运算结果为0,即a^a=0 一个数和0做异或运算结果为它本身,即a^0=a

  • 判断n的阶乘尾部有多少个0,尾部为0,说明因子中有2和5,而2能被偶数整除,n的阶乘能分解出多少个因子5

  • n & (n-1):作用是消除数字n的二进制数中的最后一个1 n & 1:作用是去掉二进制数的最后一位 这两种都可以用来计算数字中1的个数

  • 判断n是否是2的指数次幂的值, 直接 n & (n-1),一个数如果是2的指数,其二进制表示一定只有一个1

树 总结

  1. 涉及到二叉树的构造,无论普通二叉树还是二叉搜索树一定前序,都是先构造中节点。

  2. 求普通二叉树的属性,一般是后序,一般要通过递归函数的返回值做计算。

  3. 求二叉搜索树的属性,一定是中序了,要不白瞎了有序性了。

  4. 如果需要搜索整棵二叉树,那么递归函数就不要返回值,如果要搜索其中一条符合条件的路径,递归函数就需要返回值,因为遇到符合条件的路径了就要及时返回

dp 总结

背包

  1. 求组合数,for循环 外层是物品,内层是背包

  2. 求排列数,for循环 外层是背包,内层是物品

  3. 一维滚动数组,物品无限次使用,内层循环是正序;

    物品只能拿一次,内层循环是倒序

  4. 物品只能拿一次,一维滚动数组时,内层循环一定是背包

字符串 总结

  1. 字符串比较,是按位比较的,前一位相同,就会比较下一位,直到同一位能比较出结果,如果长度不一样,长度长的 大于 长度短的

比如 "12" > "11"; "12" > "1"; "13" > "120"

algorithm's People

Contributors

nixum 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.