摘要:
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++]; 阅读全文
摘要:
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 阅读全文
摘要:
方法一:动态规划 时间复杂度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];/ 阅读全文
摘要:
归并排序 class Solution { public ListNode sortList(ListNode head) { if(head == null || head.next == null) return head; ListNode fast = head,slow = head; w 阅读全文
摘要:
class Solution { public void reorderList(ListNode head) { if(head == null || head.next == null || head.next.next == null) return; ListNode mid = findM 阅读全文
摘要:
class Solution { public int countPairs(TreeNode root, int distance) { dfs(root,0,distance); return res; } private int res = 0; public List<Integer> df 阅读全文
摘要:
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 = 阅读全文
摘要:
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; 阅读全文
摘要:
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 阅读全文
摘要:
方法一:利用归并排序保存位置数组,交换时交换位置数组 class Solution { int[] count; public List<Integer> countSmaller(int[] nums) { int n = nums.length; count = new int[n]; int[ 阅读全文