leetcode速解题汇总2

本文精选了LeetCode上的经典算法题目,涵盖链表、字符串、动态规划等多个方面,包括两指针法解决移除倒数第N个节点、字符串匹配、最长有效括号等难题的解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

code Ganker:

1. Remove Nth Node From End of List -- LeetCode: 两个指针,fast先走k个节点,然后slow跟上。slow.next=slow.next.next;

2. Divide Two Integers -- LeetCode; 不能用乘除法做除法。 Sqrt(x),Pow(x,n),

3. Reverse Nodes in k-Group -- LeetCode: 翻转链表系列

4. Add two number,  add binary: 注意进位

5. Substring with Concatenation of All Words -- LeetCode:输入一个词典和一个字符串;Longest Substring Without Repeating CharactersMinimum Window Substring;输入两个字符串,包含字符串的最小串; 使用窗口把时间复杂度降低到线性的有效算法。都是使用hashmap作为窗口。

6. Longest Valid Parentheses -- LeetCode;Largest Rectangle in Histogram -- LeetCode; 这种用剩余栈的栈顶元素位置信息作为当前合法数据的判断依据是比较重要的技巧

7. Count and Say -- LeetCode: StringBuilder 字符串操作题

8. Longest Palindromic Substring -- LeetCode:返回一个最长回文子串和返回所有的最长回文子串,从中间到两边扫描;或者动态规划。

9. Combination Sum -- LeetCode:和为某一值的所有可能组合。两种情况,数组中的元素可不可以重复使用。动态规划。

10. First Missing Positive -- LeetCode: ,跟Counting sort一样,利用数组的index来作为数字本身的索引,把正数按照递增顺序依次放到数组中

11. Evaluate Reverse Polish Notation -- LeetCode:是不是逆波兰式,使用stack

12. Multiply Strings -- LeetCode:两个字符串代表的数相乘,直接对应位置相乘即可;

13. Max Points on a Line -- LeetCode: 

14. Combinations -- LeetCode:给定两个值n, k; n表示一个数,k表示有几个数表示的组成。NP问题在LeetCode中出现的频率很高,例如N-QueensSudoku SolverCombination SumPermutations等等。不过这类题目都是用一种方法而且也没有办法有时间上的提高,所以还是比较好掌握的。

15. Max Points on a Line -- LeetCode:几何问题

16. Regular Expression Matching -- LeetCode;类似的题目有Wildcard Matching;  *和.都是match;

17. LRU Cache -- LeetCode: hashMap邻接表的操作

18.  Anagrams -- LeetCode:这道题考察排序,hashmap,字符串处理;易位构词;

19. Palindrome Partitioning -- LeetCode;这道题是求一个字符串中回文子串的切割,并且输出切割结果,其实是Word Break IILongest Palindromic Substring结合

20. Clone Graph -- LeetCode: DFS, BFS

21. Gas Station -- LeetCode:这个题目的优化解法更像是一个数学题,需要定义数学模型并证明命题正确性,比较需要数学逻辑的功底。通过定义的模型以及证明的命题来做一部分贪心。

22. Copy List with Random Pointer -- LeetCode

23. Word Break II -- LeetCode: 动态规划

24. Insert Interval -- LeetCode:Merge Intervals; 插入区间和合并区间;使用ArrayList 自定义Comparator;

Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]

25. Distinct Subsequences:输入两个字符串,一个字符串包含另一个字符串出现的次数,动态规划;

26. Pascal's Triangle  -- LeetCode:这道题因为是求解每一行结果,所以空间上没什么好讲究的,Pascal's Triangle II只求解某一行的数据,反而可以在空间上进行精简,

27. Triangle -- LeetCode:三角形中最小路径和;动态规划

28. Palindrome Partitioning II -- LeetCode:回文字符串的最小切割数;动态规划

29. Path Sum II :返回所有的路径。Path sum返回路径和,前两个起始根节点;Binary Tree Maximum Path Sum;起始和终止可以是任何节点。

30. Flatten Binary Tree to Linked List -- LeetCode

31. Balanced Binary Tree -- LeetCode:Validate Binary Search Tree -- LeetCode;Convert Sorted Array|List to Binary Search Tree -- LeetCode

32.Word Search -- LeetCode:DFS;矩阵中搜索单词

33. Scramble String -- LeetCode:We say that "rgeat" is a scrambled string of "great". 动态规划

34. Maximum Product Subarray -- LeetCode:最大乘积子数组,最大和子数组类似,动态规划

35.Gray Code -- LeetCode:格雷码,二进制-数值

======================================

zjkC050818的博客

====

1. Interleaving String(Java):交叉字符串

2. Find All Anagrams in a String@Java解题报告:同字母异序词

=======================

leetcode  DERRANTCM

==============

看云==

1. 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值