没事可以刷刷leetCode
https://leetcode.com/
LeetCode 1. Two Sum
LeetCode 2.Add Two Numbers
LeetCode 3. Longest Substring Without Repeating Characters
LeetCode 4. Median of Two Sorted Arrays
LeetCode 5. Longest Palindromic Substring
LeetCode 6. ZigZag Conversion
LeetCode7. 整数反转
LeetCode 8. String to Integer(aoti)
LeetCode 9. 回文数
LeetCode 10 Regular Expression Matching
LeetCode 11.Container With Most Water
LeetCode 12. Integer to Roman
LeetCode 13.罗马数字转整数
LeetCode 14.最长公共前缀
LeetCode 15.3Sum
LeetCode 16. 3Sum Closest
LeetCode 17. Letter Combinations of a Phone Number
LeetCode 18. 4Sum
LeetCode 19. Remove Nth Node From End of List
LeetCode 20.有效的括号
LeetCode 21.合并两个有序链表
LeetCode 22.Generate Parentheses
LeetCode 23. 合并k个升序链表
LeetCode 26.删除排序数组中的重复项
LeetCode 27. 移除元素
LeetCode 28. 实现 strStr()
LeetCode 29. Divide Two Integers
LeetCode 53.最大子序和
LeetCode 771.宝石与石头
LeetCode LCP1.猜数字
leetcode题海游历
一、leetcode题目
leetcode题海游历。
7. 整数反转
链接: link.
关键点:
(1)整数范围:int的取值范围为: -231——231-1,即-2147483648——2147483647
(2)使用/ ,%运算进行获取反转值
关键逻辑:
//pop operation:
pop = x % 10;
x /= 10;//push operation:
temp = rev * 10 + pop;
rev = temp;8. 字符串转换整数 (atoi)
链接: link.
(1)去除空格函数:str.trim();
(2)判断char是否包含数字:Character.isDigit(str.charAt(i))最佳题解:https://leetcode-cn.com/problems/string-to-integer-atoi/solution/c-jian-dan-ti-jie-by-da-li-wang-2/
9. 回文数
链接: link.
不使用将数字转换成字符串的解法关键点:
1、反转数字:revertedNumber = revertedNumber * 10 + x % 10;
2、判断达到了数字的一半15. 三数之和
链接: link.
关键点:
(1)进行排序
(2)双指针方法,固定当前数,左右指针分别指向后面的队头以及队尾,向中间夹逼,相同数跳过(排除重复的组的方法)题解:https://leetcode-cn.com/problems/3sum/solution/hua-jie-suan-fa-15-san-shu-zhi-he-by-guanpengchn/
20. 有效的括号
关键点:
1、基础java接口使用:栈的使用、基础类型封装类
2、思路:对每个字符,遇到左边符号,入栈,遇到右边符号,从左边符号栈中弹出栈顶元素,进行判断是否匹配,匹配,则跳到下一个元素循环。我的题解:https://leetcode-cn.com/problems/valid-parentheses/submissions/
剑指 Offer 58 - II. 左旋转字符串
关键点:
1、String 的方法length()、charAt(m)
2、思路:
// 1、先保存strLeft
// 2、循环将strRight移动到前半部分
// 3、循环将strLeft移动到后半部分技巧:可以用取余进行循环下标替换
class Solution {
public String reverseLeftWords(String s, int n) {
String res = “”;
for(int i = n; i < n + s.length(); i++)
res += s.charAt(i % s.length());
return res;
}
}我的题解:https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/
26. 删除排序数组中的重复项
1、关键点:双指针移动进行比较,p,q,
(1)不相等,则 num[p + 1] = num[q],p++,q++
(2) 相等,,q++
2、思考:如果是这样的数组{0,1,2,3,4,5}
虽然可以判断是否相邻来执行是否移动,但实际测试判断的效率低于
3、题解:https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/solution/mian-shi-ti-58-ii-zuo-xuan-zhuan-zi-fu-chuan-qie-p/23. 合并K个升序链表
1、关键点:
(1)实现思路:分治合并,分解为合并两个list
(2)发现效率问题:三元运算符效率高于if else,少了26ms左右.可参考https://blog.csdn.net/dby73/article/details/103206805
Leetcode
每天至少一道题!
链表
leetcode24 我的题解.
leetcode116. 我的题解.
leetcode19. 我的题解.
leetcode234. 我的题解.巧用容器
贪心算法
双指针
其他