上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 15 下一页
摘要: class Solution { public int longestOnes(int[] A, int K) { int n = A.length; int res = 0, rest = K; int l = 0, r = 0; while(r < n) { int num = A[r++]; 阅读全文
posted @ 2020-07-30 10:56 Sexyomaru 阅读(73) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int numWays(int n, int k) { if(k == 0 || n == 0) return 0; if(n < 2) return k; int[] dp = new int[n]; dp[0] = k; //dp[i] 用来表示i 阅读全文
posted @ 2020-07-29 16:52 Sexyomaru 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 方法一:动态规划 时间复杂度O(n2) class Solution { public int wiggleMaxLength(int[] nums) { int n = nums.length; if(n == 0) return 0; int[][] dp = new int[n+1][2];/ 阅读全文
posted @ 2020-07-29 16:17 Sexyomaru 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 归并排序 class Solution { public ListNode sortList(ListNode head) { if(head == null || head.next == null) return head; ListNode fast = head,slow = head; w 阅读全文
posted @ 2020-07-27 15:36 Sexyomaru 阅读(77) 评论(0) 推荐(0) 编辑
摘要: class Solution { public void reorderList(ListNode head) { if(head == null || head.next == null || head.next.next == null) return; ListNode mid = findM 阅读全文
posted @ 2020-07-27 11:28 Sexyomaru 阅读(63) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int countPairs(TreeNode root, int distance) { dfs(root,0,distance); return res; } private int res = 0; public List<Integer> df 阅读全文
posted @ 2020-07-27 10:55 Sexyomaru 阅读(367) 评论(0) 推荐(0) 编辑
摘要: 1524. 和为奇数的子数组数目 class Solution { public int numOfSubarrays(int[] arr) { int n = arr.length; int sum = 0; int res = 0, odd = 0, even = 1; for(int i = 阅读全文
posted @ 2020-07-27 10:30 Sexyomaru 阅读(82) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int candy(int[] ratings) { int n = ratings.length; int[] arr = new int[n]; Arrays.fill(arr,1); // 先每人分一个 for(int i = 1; i < n; 阅读全文
posted @ 2020-07-24 17:38 Sexyomaru 阅读(103) 评论(0) 推荐(0) 编辑
摘要: class Solution { public double new21Game(int N, int K, int W) { // 先判断 K + W 是否小于N,如果是的话,说明肯定能赢得游戏,返回 1.0,也就是 100% if (N >= K + W) { return 1.0; } dou 阅读全文
posted @ 2020-07-23 22:21 Sexyomaru 阅读(84) 评论(0) 推荐(0) 编辑
摘要: 方法一:利用归并排序保存位置数组,交换时交换位置数组 class Solution { int[] count; public List<Integer> countSmaller(int[] nums) { int n = nums.length; count = new int[n]; int[ 阅读全文
posted @ 2020-07-23 21:31 Sexyomaru 阅读(176) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 15 下一页