1. Array & List

1.1Sort

Array的变更操作,好好运用尾指针:88题的end,75题的blueHead

  • 88. Merge Sorted Array (Array)
  • 75. Sort Colors
  • 21. Merge Two Sorted Lists
  • 23. Merge k Sorted Lists
  • 128. Longest Consecutive Sequence
  • 147. Insertion Sort List
  • 148. Sort List

1.2 Rejust List

两种方法:

法I:改变结构

涉及的操作主要有:

  1. 子队列中逆序
  2. 子队列与前队列连接
  3. 子队列与后队列连接

在赋值的时候前后顺序是有讲究的,先备份到tmp,然后再给它赋值

法II: 只改变值,如:Delete a node in the middle of a single linked list, fiven only access to that node. -->Solution: 把下一个节点赋值给该节点,删除下一个节点,这样就省却了寻找上一个节点的麻烦。

注意特殊节点:(以防空指针)

  1. NULL
  2. head
  3. tail

比如上题

if(n==null || n->next == null) return false;
ListNode* next = n->next;
n->data = next->data;
n->next = next->next;
  • 86. Partition List
  • 92. Reverse Linked List II
  • 61. Rotate List
  • 25. Reverse Nodes in k-Group
  • 24. Swap Nodes in Pairs
  • 143. Reorder List
  • 27. Remove Element
  • 26. Remove Duplicates from Sorted Array
  • 80. Remove Duplicates from Sorted Array II
  • 83. Remove Duplicates from Sorted List
  • 82. Remove Duplicates from Sorted List II

1.3 Search sorted array

  • 35. Search Insert Position
  • 34. Search for a Range
  • 108.Convert Sorted Array to Binary Search Tree
  • 109. Convert Sorted List to Binary Search Tree
  • 69. Sqrt(x)
  • 4.Median of Two Sorted Arrays
  • 167. Two Sum II - Input array is sorted (Array)

1.4 Search unsorted array

  • 135. Candy
  • 31. Next Permutation
  • 发帖水王 <编程之美> P130

1.5 Two Pointers

  • 15. 3Sum
  • 16. 3Sum Closest
  • 125. Valid Palindrome
  • 11.Container With Most Water
  • 19. Remove Nth Node From End of List
  • 141. Linked List Cycle
  • 142. Linked List Cycle II

1.6 双向链表

  • 146. LRU Cache

1.7 Shift

  • 通过逆序移位 <编程之美> P201
  • 字符串通过连接来代替移位 P103

2. Stack & Queue

2.1 Queue

  • 三个队列排序 p195
  • 实现带最大值查询的队列 <编程之美> P239

2.2Stack

  • 114. Flatten Binary Tree to Linked List
  • 144. Binary Tree Preorder Traversal
  • 145. Binary Tree Postorder Traversal
  • 71. Simplify Path
  • 20. Valid Parentheses
  • 32. Longest Valid Parentheses
  • 150. Evaluate Reverse Polish Notation
  • 84. Largest Rectangle in Histogram
  • 85. Maximal Rectangle
  • Implementation Stack by Array   p111
  • stack的实现(含min方法)p113
  • Hanoi p118

3. Tree

前序遍历(Pre-order Traversal):自己->左->右

  • 前序遍历用于,从上到下的遍历,左右子数的遍历依赖于根节点的数据

中序遍历(In-order Traversal):左->自己->右

前序遍历(Post-order Traversal):左->右->自己

  • 后序遍历用于,从下到上的遍历,根节点的处理依赖于左右子数的遍历结果

3.1 递归实现前序遍历

  • 112. Path Sum
  • 113. Path Sum II
  • 129. Sum Root to Leaf Numbers

3.2 递归实现中序遍历

  • 99. Recover Binary Search Tree

3.3 递归实现后序遍历

  • 124. Binary Tree Maximum Path Sum
  • 111. Minimum Depth of Binary Tree
  • 104. Maximum Depth of Binary Tree
  • 110. Balanced Binary Tree
  • 96. Unique Binary Search Trees
  • 95. Unique Binary Search Trees II
  • 101. Symmetric Tree
  • 105. Construct Binary Tree from Preorder and Inorder Traversal
  • 106. Construct Binary Tree from Inorder and Postorder Traversal

3.4“循环+栈”实现前序、中序、后序

  • 114. Flatten Binary Tree to Linked List(2.2)
  • 144. Binary Tree Preorder Traversal(2.2)
  • 145. Binary Tree Postorder Traversal(2.2)

3.5 level search(wfs)

树是一种特殊的图,在树中,广度优先搜索又称为层次搜索;深度有限搜索又分为前序、中序、后序

  • 107. Binary Tree Level Order Traversal II
  • 116. Populating Next Right Pointers in Each Node
  • 117. Populating Next Right Pointers in Each Node II
  • 127. Word Ladder

4. Graph

注意:对于不能重复遍历的情况,需要为每个节点标记是否已访问过。

4.1 遍历所有节点,两个for循环

  • 118. Pascal's Triangle
  • 119. Pascal's Triangle II
  • 120. Triangle
  • 48. Rotate Image
  • 74. Search a 2D Matrix
  • 36. Valid Sudoku

4.2 设定遍历方向,按照该方向遍历

  • 54. Spiral Matrix
  • 59. Spiral Matrix II

4.3 DFS

  • 79. Word Search
  • 73. Set Matrix Zeroes
  • 133. Clone Graph
  • 138. Copy List with Random Pointer
  • 130. Surrounded Regions

4.4 WFS

  • 126. Word Ladder II (unordered_map,map,set的使用)

4.5 Dynamic Programming

  • 64. Minimum Path Sum
  • 62. Unique Paths(为什么DP优于DFS)
  • 63. Unique Paths II

4.6 数据结构

  • bfs在大数据时通过hash表代替node marking p199
  • 稀疏矩阵的表示方法(链表、数组、三元组) <珠玑>p97 p209

4.7 着色问题

  • 点图&区间图 <编程之美> P58-60

5. Hash table, map

  • 1. Two Sum
  • 3. Longest Substring Without Repeating Characters (KMP)
  • 76. Minimum Window Substring
  • 49. Group Anagrams
  • 30. Substring with Concatenation of All Words
  • 41. First Missing Positive
  • 18. 4Sum (Hash table时间复杂度)

6. recursion

递归剪枝:

法I:最优剪枝。如果目前的结果已经差于之前得到的最优值,那么返回。

法II: 可行性剪枝。举个简单的例子,如图,问作者能否在正好第11秒的时候避过各种障碍物最终取得爱心,作者每秒能且只能移动一格,允许走重复的格子。

答案是永远不可能。因为无论怎么走,都只能在第偶数秒到达爱心,这是由他们的曼哈顿距离(两点的XY坐标差的绝对值之和)的奇偶性决定的。

6.1Recursion with backtracking 

  • 131. Palindrome Partitioning
  • 78. Subsets
  • 90. Subsets II (no duplicates)
  • 77. Combinations
  • 46. Permutations
  • 47. Permutations II (no duplicates)
  • 39. Combination Sum
  • 40. Combination Sum II (no duplicates)
  • 17.Letter Combinations of a Phone Number
  • 22. Generate Parentheses
  • 93. Restore IP Addresses
  • 44. Wildcard Matching
  • 10.Regular Expression Matching
  • 51. N-Queens
  • 52. N-Queens II
  • 37. Sudoku Solver

6.2 Divide and Conquer, 二分法

  • 50. Pow(x, n)
  • 29. Divide Two Integers

7. Dynamique programming

  • 53. Maximum Subarray
  • 134. Gas Station

线性模型:状态的排布呈线性

  • 42. Trapping Rain Water
  • 60. Permutation Sequence
  • 121. Best Time to Buy and Sell Stock
  • 122. Best Time to Buy and Sell Stock II
  • 123. Best Time to Buy and Sell Stock III
  • 70. Climbing Stairs
  • 91. Decode Ways
  • 45. Jump Game II

区间模型

  • 132. Palindrome Partitioning II
  • <编程之美> P44, 191-193
  • 139. Word Break
  • 140. Word Break II
  • 97. Interleaving String
  • 72. Edit Distance
  • 115. Distinct Subsequences
  • 87. Scramble String

8. Greedy

  • 55. Jump Game
  • 149. Max Points on a Line

9. Numerique analysis

  • 65. Valid Number
  • 66. Plus One
  • 2. Add Two Numbers
  • 67. Add Binary
  • 13. Roman to Integer
  • 12. Integer to Roman
  • 8. String to Integer (atoi)
  • 7. Reverse Integer
  • 9 Palindrome Number

10. segment, project

  • 56. Merge Intervals
  • 57. Insert Interval
  • <编程之美> P50-51

11. 字符串查找

  • 14. Longest Common Prefix
  • 28. Implement strStr()
  • 5. Longest Palindromic Substring (KMP)

12. Bit Operation

  • 89. Gray Code 
  • 136. Single Number
  • 137. Single Number II
  • p95,p140, p141,p172
  • Permutations p173
  • Parenthese p174
  • pennies p176
  • Queen 177

XIV. optimization <珠玑>

  • malloc的优化 <珠玑>p92
  • string连接的优化p100
  • 数据压缩 <珠玑>p100-101
  • 哨兵(一元数组、链表、箱、BST)<珠玑>p137
  • 随机数 <珠玑>p120(减少生成次数P125/9 未知n p125/10)

Leetcode catalogue的更多相关文章

  1. 我为什么要写LeetCode的博客?

    # 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...

  2. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  3. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  4. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  5. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  6. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  7. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  8. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  9. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

随机推荐

  1. oracle之 等待事件LOG FILE SYNC (awr)优化

    log file sycn是ORACLE里最普遍的等待事件之一,一般log file sycn的等待时间都非常短 1-5ms,不会有什么问题,但是一旦出问题,往往都比较难解决.什么时候会产生log f ...

  2. bzoj 3996 [TJOI2015]线性代数——最小割

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3996 b[ i ][ j ] 要计入贡献,当且仅当 a[ i ] = 1 , a[ j ] ...

  3. bzoj2442[Usaco2011 Open]修剪草坪——单调队列优化

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2442 考虑记录前 i 个.末尾 j 个连续选上的最大值.发现时空会爆. 又发现大量的转移形如 ...

  4. jdk1.8新特性之方法引用

    方法引用其实就是方法调用,符号是两个冒号::来表示,左边是对象或类,右边是方法.它其实就是lambda表达式的进一步简化.如果不使用lambda表达式,那么也就没必要用方法引用了.啥是lambda,参 ...

  5. 2016-the brave never die

    2016年最后一天工作日了,由于这段时间一直忙于春节项目没时间写点关于2016年的总结,回忆一下,2016年其实还有很多事情没做好,究其原因,感觉是因为对于2016年没有做任何的规划和计划,就凭着一股 ...

  6. centos 安装 Splunk

    (1).需关闭selinux: 1. vi /etc/sysconfig/selinux    SELINUX=disabled (2).开始安装mkdir  \splunk http://downl ...

  7. 如果先装framework,后装IIS,想使用ASP.NET

    32位系统在Dos下运行以下命令C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i 开始安装 ASP.NET (2.0 ...

  8. ngui自适应

    增加UIROOT using UnityEngine; namespace Com.Xyz.UI { [ExecuteInEditMode] [RequireComponent(typeof(UIRo ...

  9. ThinkPHP实例—实现登录验证

    ThinkPHP 验证 本篇我们将运用商城实例讲解一下如何运用ThinkPHP做一个登录验证 我们的框架目录结构如下图所示: 其中 app  文件夹就是我们的应用文件夹  它的目录结构如下所示 其中 ...

  10. oracle打补丁步骤简介

    1.了解opatchopatch是用于维护"个别"补丁的,有人称其为interim path或是one-off patch该命令的存放位置在$ORACLE_HOME下的OPatch ...