LeetCode 所有题目总结

文章目录

    • 做题注意事项
    • 题目分类
      • 1.位运算
      • 2.字符串题型
      • 3.TopK 问题--最大堆/最小堆
      • 4.链表
      • 5.动态规划
        • easy
        • Medium
        • hard
      • 6.贪心
      • 7.树
      • 8.图
      • 9.数学题
      • 10.数据库-SQL
      • 11.栈和队列
      • 12.矩阵
      • 13.数组
      • 14.买股票系列题目
      • 15.智力题
      • 16.并发
      • 17.线段树
      • 真实笔试,面试题
    • 其他--简单题

做题注意事项

1.注意空字符串,以及各种极端情况。
2.异或运算有奇效。
3.小心数组的开始和结束条件。

static bool _foo = ios::sync_with_stdio(false);

题目分类

1.位运算

  • LeetCode 136. Single Number–2个数直接异或–Java,C++,Python解法
  • LeetCode 137. Single Number II–三次异或消除相同的数–C++,Python解法
            seen_once = ~seen_twice & (seen_once ^ num)
            seen_twice = ~seen_once & (seen_twice ^ num)
  • LeetCode 421. Maximum XOR of Two Numbers in an Array–Python解法

2.字符串题型

具有最多两个不同字符的最长子串的长度

  • LeetCode 159. Longest Substring with At Most Two Distinct Characters --Java,C++,Python解法
  • LeetCode 771. Jewels and Stones–Java和Python解法–简单
  • LeetCode 438. Find All Anagrams in a String–字符串-滑动窗口–C++,Python解法

3.TopK 问题–最大堆/最小堆

  • LeetCode 215. Kth Largest Element in an Array–数字第K大的元素–最大堆或优先队列–C++,Python解法
  • LeetCode 973. K Closest Points to Origin–TopK 问题–最小堆–C++,Python解法
import heapq
l = heapq.nlargest(2, [3, 2, 1, 5, 6, 4])

4.链表

  • LeetCode 206 Reverse Linked List–反转链表–迭代与递归解法–递归使用一个临时变量,迭代使用3个
  • LeetCode 21. Merge Two Sorted Lists–合并2个有序列表–python递归,迭代解法
  • LeetCode 23. Merge k Sorted Lists–Python解法–优先队列,分治法
  • LeetCode 141. Linked List Cycle–百度面试编程题–C++,Python解法
    判断链表是否成环,使用快慢指针。
  • LeetCode 142. Linked List Cycle II–单向链表成环的起点–C++,Python解法
    求成环起点
  • LeetCode 2. Add Two Numbers–C++,Python解法
  • LeetCode 445. Add Two Numbers II–字节跳动面试算法题–C++,Python解法
  • LeetCode 369. Plus One Linked List–链表–C++,Python解法
  • LeetCode 148. Sort List–拼多多面试算法题–C++,Python解法
  • LeetCode 92. Reverse Linked List II–Python 解法–反转部分链表–笔试算法题

5.动态规划

easy

  • LeetCode 509. Fibonacci Number–Python解法
  • LeetCode 198. House Robber–动态规划–C++,Java,Python解法 - zhangpeterx的博客 - CSDN博客
  • LetCode 70. Climbing Stairs–动态规划-爬梯子–递归等解法 - zhangpeterx的博客 - CSDN博客
  • LeetCode 121. Best Time to Buy and Sell Stock–动态规划–Java,Python,C++解法 - zhangpeterx的博客 - CSDN博客
  • LeetCode 746. Min Cost Climbing Stairs–动态规划–Java,C++,Python解法 - zhangpeterx的博客 - CSDN博客
  • LeetCode 53. Maximum Subarray–动态规划–C++,Python解法

Medium

  • LeetCode 583. Delete Operation for Two Strings–动态规划 DP–Java,Python,C++解法 - zhangpeterx的博客 - CSDN博客
  • LeetCode 91. Decode Ways–动态规划DP的Python和Java解法 - zhangpeterx的博客 - CSDN博客
  • LeetCode 152. Maximum Product Subarray–动态规划–C++,Python解法
  • LeetCode 221. Maximal Square----动态规划–谷歌面试算法题–Python解法
  • LeetCode 542. 01 Matrix–C++解法–动态规划
  • LeetCode 542. 01 Matrix–C++解法–动态规划

hard

  • LeetCode 72. Edit Distance - zhangpeterx的博客 - CSDN博客
  • LeetCode 45. Jump Game II–Python解法–动态规划

6.贪心

  • LeetCode 122. Best Time to Buy and Sell Stock II–贪心–Java,C++,Python解法

7.树

  • LeetCode 104. Maximum Depth of Binary Tree–二叉树高度–递归或迭代–C++,Python解法
  • LeetCode 226. Invert Binary Tree–反转二叉树–递归或迭代–C++,Python解法
  • LeetCode 94. Binary Tree Inorder Traversal–二叉树中序遍历–递归,迭代–C++,Python解法
  • LeetCode 144. Binary Tree Preorder Traversal–二叉树前序遍历–反向压栈–迭代-栈,递归–C++,Python解法
  • LeetCode 145. Binary Tree Postorder Traversal–后序遍历–先序遍历反向输出–递归,迭代–C++,Python解法
  • LeetCode 589. N-ary Tree Preorder Traversal-多子节点树前序遍历–递归,迭代–反向压栈–C++解法
  • LeetCode 98. Validate Binary Search Tree–C++解法–判断是否是BST–递归,迭代做法,中序遍历
  • LeetCode 230. Kth Smallest Element in a BST–C++,Python解法–面试真题–找二叉树中第K小的元素
  • LeetCode 965 Univalued Binary Tree–判断二叉树的所有节点的值是否相同–python,java解法
  • LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List-转换二叉树为双向链表–Java,C++,Python解法
  • LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal–前序中序遍历构造二叉树-Python和Java递归,迭代解法
  • LeetCode 102. Binary Tree Level Order Traversal–递归,迭代-Python,Java解法
  • LeetCode 226. Invert Binary Tree–反转二叉树–C++,Python解法–递归,迭代做法

8.图

  • LeetCode 547. Friend Circles–Python解法–笔试算法题
  • LeetCode 207. Course Schedule–有向图找环–面试算法题–DFS递归,拓扑排序迭代–Python
  • LeetCode 399. Evaluate Division–Python-DFS解法

9.数学题

  • LeetCode 204. Count Primes–从一开始的质数个数–C++,Python解法
    不要一个一个算,快速迭代。
  • LeetCode 829. Consecutive Numbers Sum–B站笔试题–C++解法
    时间复杂度O(sqrt(n))
  • LeetCode 264. Ugly Number II–C++,Python解法
  • LeetCode 202. Happy Number–Python解法
  • LeetCode 54. Spiral Matrix–Python解法–螺旋排序
  • LeetCode 167. Two Sum II - Input array is sorted–Python解法
  • LeetCode 974. Subarray Sums Divisible by K–Python解法–数学题–取模求余
  • LeetCode 319. Bulb Switcher–C++,java,python 1行解法–数学题
  • LeetCode 268. Missing Number–Python解法–数学题
  • LeetCode 202. Happy Number–Python解法–数学题
  • LeetCode 31. Next Permutation-- Python 解法–数学题–比当前数大的最小的数
  • LeetCode 123. Best Time to Buy and Sell Stock III–Python解法–动态规划–数学题
  • LeetCode 41. First Missing Positive–Python 解法–数学题-找到不存在的最小正整数-O(1)空间复杂度

10.数据库-SQL

  • LeetCode 175. Combine Two Tables–Database–数据库题目
  • LeetCode 176. Second Highest Salary–Database–数据库题目
  • LeetCode 595 Big Countries: SQL的题

11.栈和队列

  • LeetCode 232. Implement Queue using Stacks–用2个栈来实现一个队列–C++解法
  • LeetCode 225. Implement Stack using Queues–用队列实现栈–C++解法

12.矩阵

  • LeetCode 542. 01 Matrix–C++解法–动态规划
  • LeetCode 74. Search a 2D Matrix–有序矩阵查找–python,java,c++解法

13.数组

  • LeetCode 961 N-Repeated Element in Size 2N Array --python,java解法
  • LeetCode 421. Maximum XOR of Two Numbers in an Array–Python解法
  • LeetCode 167. Two Sum II - Input array is sorted–Python解法
  • LeetCode 974. Subarray Sums Divisible by K–Python解法–数学题–取模求余
  • LeetCode 152. Maximum Product Subarray–动态规划–C++,Python解法
  • LeetCode 53. Maximum Subarray–动态规划–C++,Python解法
  • LeetCode 215. Kth Largest Element in an Array–数字第K大的元素–最大堆或优先队列–C++,Python解法

14.买股票系列题目

  • LeetCode 121. Best Time to Buy and Sell Stock–Java,Python,C++解法
  • LeetCode 122. Best Time to Buy and Sell Stock II–贪心–Java,C++,Python解法
  • LeetCode 123. Best Time to Buy and Sell Stock III–Python解法–动态规划–数学题
  • LeetCode 309. Best Time to Buy and Sell Stock with Cooldown–Java解法-卖股票系列题目

15.智力题

  • LeetCode 458. Poor Pigs–智力题「小白鼠试毒」–C++,Python解法

16.并发

  • LeetCode 1114. Print in Order–Java解法–并发问题
  • LeetCode 1115. Print FooBar Alternately–多线程并发问题–Java解法–CyclicBarrier, synchronized, Semaphore 信号量
  • LeetCode1117. Building H2O --Java解法–多线程保证执行顺序–AtomicInteger
  • LeetCode 1188. Design Bounded Blocking Queue–并发系列–Java 解法–设计有界阻塞队列–使用ArrayBlockingQueue和LinkedList

17.线段树

  • 数据结构线段树介绍与笔试算法题-LeetCode 307. Range Sum Query - Mutable–Java解法

真实笔试,面试题

  • LeetCode 468. Validate IP Address–笔试题–Python解法
  • LeetCode 141. Linked List Cycle–面试编程题–C++,Python解法
  • LeetCode 1027. Longest Arithmetic Sequence–笔试题–C++解法
  • LeetCode 17. Letter Combinations of a Phone Number–笔试题–C++,Python解法
  • LeetCode 829. Consecutive Numbers Sum–笔试题–C++解法
  • LeetCode 204. Count Primes–从一开始的质数个数–C++,Python解法
  • LeetCode 445. Add Two Numbers II–面试算法题–C++,Python解法
  • LeetCode 93. Restore IP Addresses–面试算法题–Python解法
  • LeetCode 20. Valid Parentheses–笔试题–Python解法
  • LeetCode 42. Trapping Rain Water–笔试算法题–c++解法
  • LeetCode 148. Sort List–面试算法题–C++,Python解法
  • LeetCode 221. Maximal Square----动态规划–谷歌面试算法题–Python解法
  • LeetCode 230. Kth Smallest Element in a BST–C++,Python解法–面试真题–找二叉树中第K小的元素
  • LeetCode 547. Friend Circles–Python解法–笔试算法题
  • LeetCode 226. Invert Binary Tree–反转二叉树–C++,Python解法–递归,迭代做法
    Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so f*** off.
  • LeetCode 542. 01 Matrix–C++解法–动态规划
  • LeetCode 92. Reverse Linked List II–Python 解法–反转部分链表–笔试算法题

其他–简单题

  • 单纯的排序:LeetCode 75. Sort Colors–Python解法
  • LeetCode 121. Best Time to Buy and Sell Stock–Java,Python,C++解法
  • LeetCode 1108. Defanging an IP Address–C++,Python解法
  • LeetCode 804 Unique Morse Code Words–python,java解法
  • LeetCode 709 To Lower Case – java,python解法
  • LeetCode 929 Unique Email Addresses–python一行解法,Java解法
  • LeetCode 217 Contains Duplicate–python,java解法–set–简单
  • LeetCode 657 : Robot Return to Origin
  • LeetCode 905 Sort Array By Parity–Java stream,Python lambda表达式一行 解法
  • LeetCode 22. Generate Parentheses–Python 解法–广度优先、深度优先解法 — zhang0peter的个人博客

你可能感兴趣的:(LeetCode,c++-做题,java-做题)