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. lua resty template && openresty 使用

    1. 安装 luarocks install lua-resty-template 2. 使用   配置模板页面位置     有多种方式:   a.  直接使用root 目录     代码如下:    ...

  2. FastAdmin 无刷新地址改变

    FastAdmin 无刷新地址改变 群里有人问 FastAdmin 是不是用了 pjax? 之前有看到 Karson 回复过,其实 FastAdmin 用的是 HTML5 的一个History API ...

  3. wordpress缓存插件使用提高网站速度

    WordPress是世界上使用量最多的CMS,由于程序非常吃主机性能,正常情况下当页面被访问时,使用php和mysql. 因此,系统需要消耗RAM和CPU. 如果同一时间有大量访客访问,系统将使用大量 ...

  4. php mysql 字符集(三) (转)

    http://bbs.csdn.net/topics/390097514 gbk页面插入数据到utf8表,然后取出到gbk页面 首先, 这个set names x等价于SET character_se ...

  5. MySQL主从报错解决:Failed to initialize the master info structure

    大清早收到一个MySQL的自定义语言告警 :replication interrupt,看来是主从同步报错了. 登陆MySQL,执行 show slave status \G 发现salve已经停止了 ...

  6. 今天使用VS2012遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"

    今天使用VS2012遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"   解决方法: 1.打开该项目的“属性页”对话框. 2.单击“ ...

  7. Memcached: temple

    ylbtech-Memcached: temple 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   7.返回顶部   8.返回顶部   ...

  8. NFS的安装以及windows/linux挂载linux网络文件系统NFS

    1.创建linux的NFS服务端安装centos6.4,关闭防火墙/etc/init.d/iptables status yum install nfs-utils rpcbind [root@lin ...

  9. 设置VS以管理员身份运行

    以vs2013为例 vs右键属性 ----- ​ 找到目标位置如下 "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\ ...

  10. spring aop实现拦截接口请求打印日志

    在spring配置 1编写自己的注解类 2.编写注解解析类 3.配置spring aop代理 (下面我使用注解 如使用配置 配置切点即可,有两种代理默认jdk代理 设置true 为cglib代理) / ...