LeetCode 题目解析

所有代码均是基于C++11实现,有部分代码参考了其他同学的实现。这里只做部分test,test case写的有限,并不会cover所有的Corner case。大家可以只作为参考,添加更多的test case。有些面试官会让你自己写test cases,并自己去跑测试验证自己的代码。

面试的一些小提示

1. 自我介绍可以比较简短,着重介绍自己做的成绩和产出就行了,比如在**公司的**项目中采用**方法,实现了**系统,DAU增长了**,为公司赚了**钱(为公司省了**钱);不用过多的描述项目细节。面试官会对感兴趣的点做进一步的提问。

2. 面试官问及具体的技术时,可以根据自己的工作经验和自己的项目结合进行描述,更具有说服力;不要谈空话。不然很容易被argue。

3. 技术面试的时候,面试官会跟着某个技术继续往深了问,这个时候不要急,会的就答,不会可以说暂时没有接触,后面会去学习一下;不要跟面试官杠上,不要急躁。这里更多是考察你的知识贯通能力和抗压能力。

4. 面试官让代码实现的时候一定考虑写成函数;不要自己堆在main函数里。否则50%的几率会挂掉,并且会扣掉你工作经验代码能力的分数。

5. 如果用C++最好用string或者vector;不要用char*或者数组。如果用的话,你要跟面试官证明你这样写是执行效率高或者平时用的是C语言比较多。

6. 在做一下equality check的时候,记得用“!=”;尽量不要用“==”。否则面试官会argue你,比如精度问题,字符相等问题等等。

7. 面试的时候面试官一般会给你的问题很大或者很抽象,更多不会给你很具体的问题,这个时候你一定要跟面试官交流,确认具体的问题是什么,可以适当的做假设并征求面试官的意见;不要自己按照自己思路就开始写起代码了。这个部分一般是考察你分析问题的能力和交流能力,最终达到接近问题的能力。

8. 在写代码之前,一定要跟面试官沟通你的思路,确保他们的肯定;不要拿到题就开写代码。如果得到肯定了,就能保证和他们预想的一样,你写出来的代码才有意义,否则你代码这关很容易把面试讲晕,最终fail掉。

9. 代码如果在实现的时候,有些函数忘记了,或者实在没有思路了,可以跟面试官沟通,可能会稍微扣一点分,但是影响不大。绝大多数面试官会给你提示,让你继续完成。

10. 代码完成之后,可以自己写几个test cases,先把流程跑一边;不要让面试官自己去帮你做代码检查。面试官检查到有问题,那就要扣分了;如果你自己能写一些test cases,那可能会加分,能考虑到自己加test cases说明你项目规范能力还是有的。

11. 代码描述,一定要用比较浅显的语言,比较清晰的思路把自己的代码给面试官讲解一遍;不要直接丢给面试官让他们自己去理解。当然你丢给他没有问题,面试官能力还是有的,都能看懂。这里会考察你的表达能力。

12. 如果代码到点没有完成,但是你在之前描述的思路正确,这个时候面试官一般会犹豫是否给你通过,这个时候要跟面试官沟通;不要灰心,也不要觉得自己反正是挂了,破罐子破摔。在这种摇摆定的时候,能不能通过就在面试官的一念之间。

13. 面试完成,面试官一般会让你问问题,这个时候一定要问;不要说自己没有问题。这里考察你是否对目前职位和公司感兴趣,可以问:面试的岗位是做什么工作的;这个岗位需要什么技术;公司是否对这个项目是否重视;大概需要招几个人;也可以问问面试对技术未来发展有什么看法。

题目目录

.
├── 1. Linear List
|   ├── 1.1 Array
|   |   ├── 1.1.1 Remove Duplicates from Sorted Array
|   |   ├── 1.1.2 Remove Duplicates from Sorted Array II
|   |   ├── 1.1.3 Search in Rotated Sorted Array
|   |   ├── 1.1.4 Search in Rotated Sorted Array II
|   |   ├── 1.1.5 Median of Two Sorted Arrays
|   |   ├── 1.1.6 Longest Consecutive Sequence
|   |   ├── 1.1.7 Two Sum
|   |   ├── 1.1.8 3Sum
|   |   ├── 1.1.9 3Sum Closest
|   |   ├── 1.1.10 4Sum
|   |   ├── 1.1.11 Remove Element
|   |   ├── 1.1.12 Next Permutation
|   |   ├── 1.1.13 Permutation Sequence
|   |   ├── 1.1.14 Valid Sudoku
|   |   ├── 1.1.15 Trapping Rain Water
|   |   ├── 1.1.16 Rotate Image
|   |   ├── 1.1.17 Plus One
|   |   ├── 1.1.18 Climbing Stairs
|   |   ├── 1.1.19 Gray Code
|   |   ├── 1.1.20 Set Matrix Zero
|   |   ├── 1.1.21 Gas Station
|   |   ├── 1.1.22 Candy
|   |   ├── 1.1.23 Single Number
|   |   └── 1.1.24 Single Number II
|   |
|   └── 1.2 Link List
|       ├── 1.2.1 Add Two Numbers
|       ├── 1.2.2 Reverse Linked List II
|       ├── 1.2.3 Partition List
|       ├── 1.2.4 Remove Duplicates From Sorted List
|       ├── 1.2.5 Remove Duplicates From Sorted List II
|       ├── 1.2.6 Rotate List
|       ├── 1.2.7 Remove Nth Node From End of List
|       ├── 1.2.8 Swap Nodes in Pairs
|       ├── 1.2.9 Reverse Nodes in k-Group
|       ├── 1.2.10 Copy List with Random Pointer
|       ├── 1.2.11 Linked List Cycle
|       ├── 1.2.12 Linked List Cycle II
|       ├── 1.2.13 Reorder List
|       └── 1.2.14 LRU Cache
|
|
├── 2. Character String
|   ├── 2.1 Valid Palindrome
|   ├── 2.2 Implement strStr()
|   ├── 2.3 String to Integer (atoi)
|   ├── 2.4 Add Binary
|   ├── 2.5 Longest Palindromic Substring
|   ├── 2.6 Regular Expression Matching
|   ├── 2.7 Wildcard Matching
|   ├── 2.8 Longest Common Prefix
|   ├── 2.9 Valid Number
|   ├── 2.10 Integer to Roman
|   ├── 2.11 Roman to Integer
|   ├── 2.12 Count and Say
|   ├── 2.13 Anagrams
|   ├── 2.14 Simplify Path
|   └── 2.15 Length of Last Word
|
|
├── 3. Stack and Queue
|   ├── 3.1 Stack
|   |   ├── 3.1.1 Valid Paraentheses
|   |   ├── 3.1.2 Longest Valid Parantheses
|   |   ├── 3.1.3 Largest Rectangle in Histogram
|   |   └── 3.1.4 Evaluate Reverse Polish Notation
|   |
|   └── 3.2 Queue
|       └── ... (Used in other sections)
|
|
├── 4. Tree
|   ├── 4.1 Binary Tree Traversal
|   |   ├── 4.1.1 Bianry Tree Preorder Traversal
|   |   ├── 4.1.2 Bianry Tree Inorder Traversal
|   |   ├── 4.1.3 Bianry Tree Postorder Traversal
|   |   ├── 4.1.4 Bianry Tree Level Order Traversal
|   |   ├── 4.1.5 Bianry Tree Level Order Traversal II
|   |   ├── 4.1.6 Binary Tree Zigzag Level Order Traversal
|   |   ├── 4.1.7 Recover Binary Search Tree
|   |   ├── 4.1.8 Same Tree
|   |   ├── 4.1.9 Symmetric Tree
|   |   ├── 4.1.10 Balanced Binary Tree
|   |   ├── 4.1.11 Flatten Binary Tree to Linked List
|   |   └── 4.1.12 Populating Next Right Pointers in Each Node II
|   |
|   ├── 4.2 Binary Tree Construction
|   |   ├── 4.2.1 Construct Binary Tree from Inorder and Postorder Traversal
|   |   └── 4.2.2 Construct Binary Tree from Preorder and Inorder Traversal
|   | 
|   ├── 4.3 Binary Tree Finding
|   |   ├── 4.3.1 Unique Binary Search Trees
|   |   ├── 4.3.2 Unique Binary Search Trees II
|   |   ├── 4.3.3 Validate Binary Search Tree
|   |   ├── 4.3.4 Convert Sorted Array to Binary Search Tree
|   |   └── 4.3.5 Convert Sorted List to Binary Search Tree
|   | 
|   └── 4.4 Binary Tree Recursion
|       ├── 4.4.1 Minimum Depth of Binary Tree
|       ├── 4.4.2 Maximum Depth of Binary Tree
|       ├── 4.4.3 Path Sum
|       ├── 4.4.4 Path Sum II
|       ├── 4.4.5 Binary Tree Maximum Path Sum
|       ├── 4.4.6 Populating Next Right Pointers in Each Node
|       └── 4.4.7 Sum Root to Leaf Numbers
|
|
├── 5. Sort
|   ├── 5.1 Merge Sorted Array
|   ├── 5.2 Merge Two Sorted Lists
|   ├── 5.3 Merge k Sorted Lists
|   ├── 5.4 Insertion Sort List
|   ├── 5.5 Sort List
|   ├── 5.6 First Missing Positive
|   └── 5.7 Sort Colors
|
|
├── 6. Find
|   ├── 6.1 Search for a Range
|   ├── 6.2 Search Insert Position
|   └── 6.3 Search a 2D Matrix
|
|
├── 7. Brute-force
|   ├── 7.1 Subsets
|   ├── 7.2 Subsets II
|   ├── 7.3 Permutations
|   ├── 7.4 Next Permutations II
|   └── 7.5 Letter Combinations of a Phone Number
|
|
├── 8. Breadth First Search
|   ├── 8.1 Word Ladder
|   ├── 8.2 Word Ladder II
|   └── 8.3 Surrounded Regions
|
|
├── 9. Depth First Search
|   ├── 9.1 Palindrome Partitioning
|   ├── 9.2 Unique Paths
|   ├── 9.3 Unique Paths II
|   ├── 9.4 N-Queens
|   ├── 9.5 N-Queens II
|   ├── 9.6 Restore IP Address
|   ├── 9.7 Combination Sum
|   ├── 9.8 Combination Sum II
|   ├── 9.9 Generate Parentheses
|   ├── 9.10 Sudoku Solver
|   └── 9.11 Word Search
|
|
├── 10. Divide and Conquer
|   ├── 10.1 Pow(x, n)
|   └── 10.2 Sqrt(x)
|
|
├── 11. Greedy
|   ├── 11.1 Jump Game
|   ├── 11.2 Jump Game II
|   ├── 11.3 Best Time to Buy and Sell Stock
|   ├── 11.4 Best Time to Buy and Sell Stock II
|   ├── 11.5 Longest Substring without Repeating Characters
|   └── 11.6 Container with Most Water
|
|
├── 12. Dynamic Programming
|   ├── 12.1 Triangle
|   ├── 12.2 Maximum Subarray
|   ├── 12.3 Palindrome Partitioning II
|   ├── 12.4 Maximal Rectangle
|   ├── 12.5 Best Time to Buy and Sell Stock III
|   ├── 12.6 Interleaving String
|   ├── 12.7 Scramble String
|   ├── 12.8 Minimum Path Sum
|   ├── 12.9 Edit Distance
|   ├── 12.10 Decode Ways
|   ├── 12.11 Distinct Subsequences
|   ├── 12.12 Word Break
|   └── 12.13 Word Break II
|
|
├── 13. Graph
|   └── 13.1 Clone Graph
|
|
└── 14. Details Checking
    ├── 14.1 Reverse Integer
    ├── 14.2 Palindrome Number
    ├── 14.3 Insert Interval
    ├── 14.4 Merge Interval
    ├── 14.5 Minimum Window Substring
    ├── 14.6 Multiply Strings
    ├── 14.7 Substring with Concatenation of All Words
    ├── 14.8 Pascal's Triangle
    ├── 14.9 Pascal's Triangle II
    ├── 14.10 Spiral Matrix
    ├── 14.11 Spiral Matrix II
    ├── 14.12 ZigZag Conversion
    ├── 14.13 Divide Two Integers
    ├── 14.14 Text Justification
    └── 14.15 Max Points on a Line

参考:LiveToolkit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值