Giter Club home page Giter Club logo

leetcode's Introduction

leetcode

偶尔做一做,要保持手感

环境

Goland中配置LeetCode Editor插件,自定义模板
Code FileName:

$!{question.frontendQuestionId}-${question.titleSlug}

Code Template:

package main
// ${question.frontendQuestionId} ${question.titleSlug} $!velocityTool.date()

${question.code}

func main() {

}

总结

链表

链表中点

依据快慢指针原理,快指针结束时,慢指针到中点

  • 循环条件为 fast.next and fast.next
    • 节点个数为奇数时,slow节点落在中间节点上
    • 节点个数为偶数数时,slow节点落在中间节点的左边一侧上
  • 循环条件为 fast.next and fast.next.next
    • 节点个数为奇数时,slow节点落在中间节点上
    • 节点个数为偶数数时,slow节点落在中间节点的右边一侧上

二分查找

链接

右边界的选择

区间开闭带来的区别

  1. 计算 mid 时要防止溢出,可以使用 mid = left + (right - left) >> 1 的写法
  2. 如果 right 初始化为 len(nums)(数组长度),
    1. 循环的判断条件为 left < right
    2. 循环中 right 的赋值表达式为 right = mid left=mid+1
  3. 如果 right 初始化为 len(nums) - 1(索引最大值)
    1. 循环的判断条件为 left <= right
    2. 循环中 right 的赋值表达式为 right = mid - 1 left=mid+1

位操作

异或操作

比如 136 只出现一次的数字,就利用以下三个规律,全部异或后得出

  • 任何数和 0 做异或运算,结果仍然是原来的数
  • 任何数和其自身做异或运算,结果是 0
  • 异或运算满足交换律和结合律

二进制中1的个数

n & (n-1) 的操作,可以将 n 对应的二进制最右侧的 1 置为 0

动态规划

回溯

前缀和

leetcode's People

Contributors

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