上一页 1 2 3 4 5 6 7 8 9 ··· 33 下一页
摘要: 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) { 阅读全文
posted @ 2020-08-21 14:54 欣姐姐 阅读(74) 评论(0) 推荐(0) 编辑
摘要: 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 += 阅读全文
posted @ 2020-08-21 14:52 欣姐姐 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 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; } 阅读全文
posted @ 2020-08-21 12:02 欣姐姐 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2020-08-21 11:57 欣姐姐 阅读(87) 评论(0) 推荐(0) 编辑
摘要: 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 = 阅读全文
posted @ 2020-08-21 11:09 欣姐姐 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 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( 阅读全文
posted @ 2020-08-21 09:41 欣姐姐 阅读(76) 评论(0) 推荐(0) 编辑
摘要: public MedianFinder() { } PriorityQueue<Integer> max = new PriorityQueue<>(); PriorityQueue<Integer> min = new PriorityQueue<Integer>(11,new Comparato 阅读全文
posted @ 2020-08-21 09:11 欣姐姐 阅读(87) 评论(0) 推荐(0) 编辑
摘要: public int[] getLeastNumbers(int[] arr, int k) { //最小的k个数 Arrays.sort(arr); return Arrays.copyOfRange(arr,0,k); } public int[] getLeastNumbers(int[] a 阅读全文
posted @ 2020-08-21 09:10 欣姐姐 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 暴力法: class Solution { public int majorityElement(int[] nums) { //最容易想到暴力法 int n = nums.length; if(n==1) return nums[0]; Map<Integer,Integer> map = new 阅读全文
posted @ 2020-08-20 16:06 欣姐姐 阅读(111) 评论(0) 推荐(0) 编辑
摘要: public String[] permutation(String s) { //显然是递归加回溯 char[] c = s.toCharArray(); int n = c.length; //可能有重复元素,所以用set来存储, Set<String> set = new HashSet<>( 阅读全文
posted @ 2020-08-20 14:55 欣姐姐 阅读(89) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 33 下一页