![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
力扣
DMDMCAR
这个作者很懒,什么都没留下…
展开
-
LeetCode 19 删除链表的倒数第 N 个结点
编程语言:Java题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/题解:递归即可,注意的是,要是被翻转的位置刚好是开头,则需要手动处理,因为递归中并没有处理。难度:Medium结果:ACclass Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(gogo(head, n)!=n)原创 2022-04-24 19:05:38 · 976 阅读 · 0 评论 -
LeetCode 53 最大子数组和
编程语言:Java题目链接:https://leetcode-cn.com/problems/maximum-subarray/题解:无,不想进阶,,,难度:easy结果:ACclass Solution { public int maxSubArray(int[] nums) { int sum=0; int res=Integer.MIN_VALUE; for(int i=0;i<nums.length;i++){原创 2022-04-24 17:07:40 · 141 阅读 · 0 评论 -
LeetCode 18 四数之和
编程语言:Java题目链接:https://leetcode-cn.com/problems/4sum/题解:其他都简单,主要是剪枝,为了让大家能看懂,注释写的满满的。难度:Medium结果:以后就不放图片了,好麻烦class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { List<List<Integer>> res = ne原创 2022-04-24 16:54:43 · 102 阅读 · 0 评论 -
LeetCode 22 括号生成
编程语言:Java题目链接:https://leetcode-cn.com/problems/generate-parentheses/题解:也可以使用StringBuilder,记得每次要恢复状态即可,第一个AC是用了StringBuilder的。难度:Medium结果:class Solution { static List<String> list=new LinkedList<>(); public List<String> gen原创 2022-04-23 20:06:12 · 319 阅读 · 0 评论 -
LeetCode 21 合并两个有序链表
编程语言:Java题目链接:https://leetcode-cn.com/problems/merge-two-sorted-lists/题解:水题,但递归写法,确实一开始没想到,然后自己做的时候还定义了辅助空间,菜了。难度:easy结果:正常写法:class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { ListNode list=new ListNode(0,n原创 2022-04-23 19:47:13 · 1406 阅读 · 0 评论 -
LeetCode 20 有效的括号
编程语言:Java题目链接:https://leetcode-cn.com/problems/valid-parentheses/题解:水题,这几天没时间,继续做水题难度:easy结果:class Solution { static String str = "()[]{}"; public boolean isValid(String s) { Deque<Character> que = new LinkedList<>();原创 2022-04-23 19:17:26 · 285 阅读 · 0 评论 -
LeetCode 16 最接近的三数之和
编程语言:Java题目链接:https://leetcode-cn.com/problems/3sum-closest/题解:最开始是暴力的,看了题解觉得自己是**难度:Medium结果:class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int res = nums[0] + nums[1] + nums[2];原创 2022-04-21 21:00:28 · 397 阅读 · 0 评论 -
LeetCode 12 整数转罗马数字
编程语言:Java题目链接:https://leetcode-cn.com/problems/integer-to-roman/题解:水题难度:Medium结果:class Solution { public String intToRoman(int num) { int[]a={1000,900,500,400,100,90,50,40,10,9,5,4,1}; String[]b={"M","CM","D","CD","C","XC","L","XL原创 2022-04-21 20:41:22 · 422 阅读 · 0 评论 -
LeetCode 17 电话号码的字母组合
编程语言:Java题目链接:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/题解:水题难度:Medium结果:class Solution { static List<String> list; static String[][] strs={ {"a","b","c"}, {"d","e","f"}, {"g","h","i"原创 2022-04-21 20:11:34 · 413 阅读 · 0 评论 -
LeetCode 10 正则表达式匹配
编程语言:Java题目链接:https://leetcode-cn.com/problems/regular-expression-matching/题解:看注释,太菜了,搬题解。结果:class Solution { public boolean isMatch(String s, String p) { if (s != null && p != null) { int m = s.length(); in原创 2022-04-15 16:04:00 · 339 阅读 · 0 评论 -
LeeCode 6 Z 字形变换
编程语言:Java题目链接:https://leetcode-cn.com/problems/zigzag-conversion/description/题解:大体思路为直接根据输出格式进行一行一行的输出,但是要分情况:①第一行和最后一行一直加同一个数即可,这个数的值显而易见;②中间行,时而加多一点,时而加少一点,故需要记录状态,以便确定下一个位移的步数。难度:Medium结果:class Solution { public String convert(String s, int nu原创 2022-04-15 11:28:16 · 223 阅读 · 0 评论