摘要:
class Solution { int res; int k; public int kthLargest(TreeNode root, int k) { this.k = k; dfs(root); return res; } private void dfs(TreeNode root) { 阅读全文
摘要:
public int countDigitOne(int n) { int digit = 1, res = 0; int high = n / 10, cur = n % 10, low = 0; while(high != 0 || cur != 0) { if(cur == 0) res += 阅读全文
摘要:
public int missingNumber(int[] nums) { int n = nums.length; int i = 0; while(i<n){ if(nums[i]!=i) return i; else{ i++; } } return n; } 阅读全文
摘要:
public int search(int[] nums, int target) { int len = nums.length; int i = 0,j = -1; while(i<len){ if(nums[i] == target){ j = i+1; while(j<len){ if(nu 阅读全文
摘要:
class Solution { public char firstUniqChar(String s) { int len = s.length(); Set<Character> set = new HashSet<>(); for(int i = 0;i<len;i++){ char ch = 阅读全文
摘要:
class Solution { public int maxSubArray(int[] nums) { //动态规划 int len = nums.length; int[] res = new int[len]; int max = nums[0]; res[0] = nums[0]; if( 阅读全文
摘要:
public MedianFinder() { } PriorityQueue<Integer> max = new PriorityQueue<>(); PriorityQueue<Integer> min = new PriorityQueue<Integer>(11,new Comparato 阅读全文
摘要:
public int[] getLeastNumbers(int[] arr, int k) { //最小的k个数 Arrays.sort(arr); return Arrays.copyOfRange(arr,0,k); } public int[] getLeastNumbers(int[] a 阅读全文