Git Product home page Git Product logo

leetcode-1's Introduction

LeetCode算法题解

个人算法实践,详细注释,提供多种解体方案和思路。

二分查找

专题文章:双指针技巧总结

二分法一般针对已经排好序的数组

// 二分法套路
function dichotomy() {
    // 左边界
    var left ...
    // 右边界
    var right ...
    // 记录答案
    var ans
    while(left <= right) {
        // 中间值
        var middle = Math.floor((left + right) / 2)
        // 猜测是否满足条件
        if (guess(middle, ...)) {
            // 如果满足条件,记录答案
            ans = middle
            // 缩小搜索范围,在更小的值中搜索
            right = middle - 1
        } else  {
            // 在更大的值中搜索
            left = middle + 1
        }
    }
    return ans
}

更多二分法技巧

二叉树

专题文章:二叉树的深度优先遍历与广度优先遍历

String

技巧题

许多算法题,除了数据结构外,还有许多是解题思路。换个思维方式或许有更多解法。

分治(递归)

递归是分治算法**最常用方法。

递归的三大要素:

  • 第一要素:明确你这个函数想要干什么
  • 第二要素:寻找递归结束条件
  • 第三要素:找出函数的等价关系式(不断缩小参数的范围)

有关递归的一些优化思路:

  1. 考虑是否重复计算
  2. 考虑是否可以自底向上

动态规划

参考

leetcode-1's People

Contributors

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