水下功夫做透,水上才能顺风顺水。
摘要: public ListNode rotateRight(ListNode head, int k) { if(head==null||head.next==null||k==0){ return head; } ListNode slow = head; ListNode fast = head; 阅读全文
posted @ 2022-03-05 21:00 北方寒士 阅读(17) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。(只求最大子序和,不是最大子序区间) 思路 假设 nums 阅读全文
posted @ 2022-03-05 20:20 北方寒士 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 动态方程:d[i][j] = (a[i]=a[j])&&d[i+1][j-1]public String longestPalindrome(String str) { if (str==null||str.length()==1) { return str; } int len = str.len 阅读全文
posted @ 2022-03-05 19:57 北方寒士 阅读(24) 评论(0) 推荐(0) 编辑
摘要: public ListNode removeNthFromEnd(ListNode head, int n) { ListNode before = head; ListNode after = head; if(head==null){ return null; } while(n!=0){ be 阅读全文
posted @ 2022-03-05 18:52 北方寒士 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标public int[] twoSum(int[] nums, int target) { int[] a = new int[2]; Map<Intege 阅读全文
posted @ 2022-03-05 11:49 北方寒士 阅读(11) 评论(0) 推荐(0) 编辑
摘要: public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode res = new ListNode(); ListNode cur = res; int sum = 0; int carry = 0; while(l1!=nul 阅读全文
posted @ 2022-03-05 11:35 北方寒士 阅读(59) 评论(0) 推荐(0) 编辑