leetcode周赛
z_jary
这个作者很懒,什么都没留下…
展开
-
leetcode周赛补完计划(一)
周赛133 leetcode 1029.两地调度 解题思路:按每个人飞往A市和B市费用的差值排序,取其中差值大,费用少的选项,满足有N人飞往A市或B市后,剩余人全部飞往剩下的城市 public int twoCitySchedCost(int[][] costs) { int h = costs.length; int min = 0; int a = 0,b = 0; ...原创 2019-06-03 12:45:22 · 163 阅读 · 0 评论 -
leetcode1108-1111、1114-1117
1108.IP地址无效化 public String defangIPaddr(String address) { StringBuffer res = new StringBuffer(); for(int i = 0;i < address.length();i++){ char c = address.charAt(i); if(c !=...原创 2019-08-29 13:37:36 · 222 阅读 · 0 评论 -
leetcode1093-1096、1103-1106
周赛142 大样本统计 public double[] sampleStats(int[] count) { double min = 256,max = 0,avg,mode = 0,mid = 0,mmaxnum = 0,sum = 0,c = 0; for(int i = 0;i < 256;i++) { if(count[i] != 0){ ...原创 2019-08-14 13:37:32 · 177 阅读 · 0 评论 -
leetcode周赛补完计划(八)
周赛140 Bigram 分词 public String[] findOcurrences(String text, String first, String second) { String[] str = text.split(" "); ArrayList<String> reslist = new ArrayList<>(); for(...原创 2019-07-07 15:09:03 · 74 阅读 · 0 评论 -
leetcode周赛补完计划(九)
周赛141 复写零 public void duplicateZeros(int[] arr) { for(int i = 0;i < arr.length - 1;i++){ if(arr[i] == 0){ for(int j = arr.length - 1;j > i;j--){ arr[j] ...原创 2019-07-16 09:43:09 · 93 阅读 · 0 评论 -
leetcode周赛补完计划(六)
周赛138 leetcode 1051. 高度检查器 解题思路:排序数组然后比对原始数组,顺手写个快速排序 public int heightChecker(int[] heights) { int[] original = heights.clone(); qsort(heights,0,heights.length-1); int num = 0; for(in...原创 2019-06-03 21:59:46 · 87 阅读 · 0 评论 -
leetcode周赛补完计划(五)
周赛137 leetcode 1046. 最后一块石头的重量 public int lastStoneWeight(int[] stones) { PriorityQueue<Integer> q = new PriorityQueue<>(new Comparator<Integer>(){ @Override publ...原创 2019-06-03 16:51:56 · 87 阅读 · 0 评论 -
leetcode周赛补完计划(四)
周赛136 leetcode 1041. 困于环中的机器人 解题思路:走完一次循环后假如机器人不在原位且方向不变,则不能成环 public boolean isRobotBounded(String instructions) { char[] ins = instructions.toCharArray(); int len = ins.length; int[] ori...原创 2019-06-03 16:09:23 · 92 阅读 · 0 评论 -
leetcode周赛补完计划(三)
周赛135 leetcode 1037.有效的回旋镖 解题思路:就是判断三角形的问题,用的斜率方法,坐标抽平行另处理,未优化 public boolean isBoomerang(int[][] points) { if((points[0][0] == points[1][0] && points[0][1] == points[1][1]) || ...原创 2019-06-03 14:28:56 · 112 阅读 · 0 评论 -
leetcode周赛补完计划(七)
周赛139 字符串的最大公因子 解题思路:辗转相除 public String gcdOfStrings(String str1, String str2) { while (str1.length() >0 && str2.length() > 0){ if(str1.length() < str2.length()){ ...原创 2019-06-19 13:08:26 · 76 阅读 · 0 评论 -
leetcode周赛补完计划(二)
周赛134 leetcode 1033. 移动石子直到连续 public int[] numMovesStones(int a, int b, int c) { int max = 0,min = 0; int[] res = {min,max}; int[] order = {a,b,c}; Arrays.sort(order); if(order[1] ...原创 2019-06-03 13:07:15 · 171 阅读 · 0 评论 -
leetcode1122-1125
数组的相对排序 public int[] relativeSortArray(int[] arr1, int[] arr2) { HashMap<Integer,Integer> count = new HashMap<>(); for(int i:arr1){ if(count.containsKey(i)){ ...原创 2019-08-29 13:40:30 · 182 阅读 · 0 评论