| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + public class LeetCode_373_95 { | ||
| 2 | + public List<int[]> kSmallestPairs(int[] nums1, int[] nums2, int k) { | ||
| 3 | + List<int[]> res = new LinkedList<>(); | ||
| 4 | + Queue<int[]> queue = new PriorityQueue<>(k,new Comparator<int[]>(){ | ||
| 5 | + public int compare(int[] o1,int[] o2){ | ||
| 6 | + int tmp1 = o1[0]+o1[1]; | ||
| 7 | + int tmp2 = o2[0]+o2[1]; | ||
| 8 | + | ||
| 9 | + return tmp1 - tmp2; | ||
| 10 | + } | ||
| 11 | + }); | ||
| 12 | + | ||
| 13 | + for(int i = 0;i<nums1.length;i++){ | ||
| 14 | + for(int j = 0;j<nums2.length;j++){ | ||
| 15 | + queue.add(new int[]{nums1[i],nums2[j]}); | ||
| 16 | + } | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + while(k-->0){ | ||
| 20 | + int[] tmp = queue.poll(); | ||
| 21 | + if(tmp == null) | ||
| 22 | + break; | ||
| 23 | + res.add(tmp); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + return res; | ||
| 27 | + } | ||
| 28 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + class LeetCode_997_95 { | ||
| 2 | + public int findJudge(int N, int[][] trust) { | ||
| 3 | + int i,j; | ||
| 4 | + int[] res = new int[N]; | ||
| 5 | + int[] flag = new int[N]; | ||
| 6 | + for(i=0;i<trust.length;i++) { | ||
| 7 | + flag[trust[i][0]-1]=1;//信任了别人,不可能是法官 | ||
| 8 | + res[trust[i][1]-1]++; //统计这个人被信任的次数 | ||
| 9 | + } | ||
| 10 | + for(i=0;i<N;i++) { | ||
| 11 | + if(res[i]==N-1 && flag[i]==0) { | ||
| 12 | + return i+1; | ||
| 13 | + } | ||
| 14 | + } | ||
| 15 | + return -1; | ||
| 16 | + } | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + class LeetCode_455_95 { | ||
| 2 | + public int findContentChildren(int[] g, int[] s) { | ||
| 3 | + int count = 0; | ||
| 4 | + | ||
| 5 | + Arrays.sort(g); | ||
| 6 | + Arrays.sort(s); | ||
| 7 | + | ||
| 8 | + for (int i = 0,j = 0; i < g.length && j < s.length; ) | ||
| 9 | + if (g[i] <= s[j]){ | ||
| 10 | + count++; | ||
| 11 | + i++; | ||
| 12 | + j++; | ||
| 13 | + }else j++; | ||
| 14 | + | ||
| 15 | + return count; | ||
| 16 | + } | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + class LeetCode_784_95 { | ||
| 2 | + public List<String> letterCasePermutation(String S) { | ||
| 3 | + List<String> list = new ArrayList<>(); | ||
| 4 | + String temp = ""; | ||
| 5 | + letter(list,S,temp,0); | ||
| 6 | + return list; | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + public static void letter(List<String> list,String S, String temp , int index){ | ||
| 10 | + | ||
| 11 | + if (S.length() == temp.length()) list.add(temp); | ||
| 12 | + | ||
| 13 | + if (index == S.length()) return; | ||
| 14 | + | ||
| 15 | + temp+=S.charAt(index); | ||
| 16 | + letter(list,S,temp,index+1); | ||
| 17 | + temp = temp.substring(0,temp.length()-1); | ||
| 18 | + | ||
| 19 | + if (S.charAt(index) >= 'a' && S.charAt(index) <= 'z'){//小写字母a-z | ||
| 20 | + temp += (char)(S.charAt(index) + 'A' - 'a'); | ||
| 21 | + letter(list,S,temp,index+1); | ||
| 22 | + }else if(S.charAt(index) >= 'A' && S.charAt(index) <= 'Z'){//大写字母A-Z | ||
| 23 | + temp += (char)(S.charAt(index) + 'a' - 'A'); | ||
| 24 | + letter(list,S,temp,index+1); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + } | ||
| 28 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments