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. 如何使用 nslookup 查域名的 ttl

    如何使用 nslookup 查域名的 ttl nslookup 经常用,但是最近才使用到查 ttl 的信息. 域名的 ttl 也是网站优化的一个重要参数. nslookup -d www.fastad ...

  2. 关于SQL的几道小题详解

    关于SQL的几道小题详解 当我们拿到题目的时候,并不是急于作答,那样会得不偿失的,而是分析思路,采用什么方法,达到什么目的,还要思考有没有简单的方法或者通用的方法等等,这样才会达到以一当十的效果,这样 ...

  3. 使用JDK合成照片

    原图(工程所在目录7098849.jpg): 头像(工程所在目录20181023201750.jpg): 开始合成(执行如下main方法): public static void main(Strin ...

  4. Windows Driver Kit Version 7.1.0 ( 也就是 7600.16385.1 ) 下载地址

    Windows Driver Kit Version 7.1.0 ( 也就是 7600.16385.1 ) 下载地址 http://download.microsoft.com/download/4/ ...

  5. 在Mac下配置php开发环境:Apache+php+MySql (卡在 给mysql 设置不了账号密码)

    https://my.oschina.net/joanfen/blog/171109#OSC_h4_3 cmd 进入mysql的方法

  6. java代码啊==indexOf()方法返回字符第一次出现的位置

    package com.s.x; public class Wang { public static void main(String[] args) { if ("woaini" ...

  7. 04:Sysbench压测-innodb_flush_log_at_trx_commit,sync_binlog参数对性能的影响

    目录 sysbench压测-innodb_flush_log_at_trx_commit,sync_binlog参数对性能的影响 一.OLTP测试前准备 二.MySQL 数据落盘的过程 三.参数说明 ...

  8. 022:SQL优化--JOIN算法

    目录 一. SQL优化--JOIN算法 1.1. JOIN 写法对比 2. JOIN的成本 3. JOIN算法 3.1. simple nested loop join 3.2. index nest ...

  9. golang的吐槽

    烂到极致的包管理:简单清晰的包管理机制是任何一门语言都需要具备的.后起之秀的golang,在众多成熟的其他语言包管理方式,居然做成这样,简直人间地狱.

  10. SHUTDOWN: waiting for active calls to complete

    Problem Description: ====================  You are attempting to shut down the database and the data ...