id
int64
0
1.17k
comefrom
stringlengths
21
84
code
stringlengths
50
1.89k
masked
stringlengths
63
2.47k
200
<awangdev>Maximum Subarray II_4.java
public int maxTwoSubArrays(ArrayList<Integer> nums) { if (nums == null || nums.size() == 0) { return 0; } int preSum = 0; int minPreSum = 0; int max = Integer.MIN_VALUE; int n = nums.size(); int[] left = new int[n]; int[] right = new int[n]; for (int i = 0; i < n; i++) { preSum += nums.get(i); max = Math.max(max, preSum - minPreSum); minPreSum = Math.min(minPreSum, preSum); left[i] = max; } preSum = 0; minPreSum = 0; max = Integer.MIN_VALUE; for (int i = n - 1; i >= 0; i--) { preSum += nums.get(i); max = Math.max(max, preSum - minPreSum); minPreSum = Math.min(minPreSum, preSum); right[i] = max; } max = Integer.MIN_VALUE; for (int i = 0; i < n - 1; i++) { int rst = left[i] + right[i + 1]; max = Math.max(max, rst); } return max; }
public int sample_funcname ( ArrayList < Integer > var_2 ) { if ( var_2 == null || var_2 . size ( ) == 0 ) { return 0 ; } int var_6 = 0 ; int var_7 = 0 ; int max = Integer . MIN_VALUE ; int var_10 = var_2 . size ( ) ; int [ ] var_11 = new int [ var_10 ] ; int [ ] var_12 = new int [ var_10 ] ; for ( int var_13 = 0 ; var_13 < var_10 ; var_13 ++ ) { var_6 += var_2 . get ( var_13 ) ; max = Math . max ( max , var_6 - var_7 ) ; var_7 = Math . min ( var_7 , var_6 ) ; var_11 [ var_13 ] = max ; } var_6 = 0 ; var_7 = 0 ; max = Integer . MIN_VALUE ; for ( int var_13 = var_10 - 1 ; var_13 >= 0 ; var_13 -- ) { var_6 += var_2 . get ( var_13 ) ; max = Math . max ( max , var_6 - var_7 ) ; var_7 = Math . min ( var_7 , var_6 ) ; var_12 [ var_13 ] = max ; } max = Integer . MIN_VALUE ; for ( int var_13 = 0 ; var_13 < var_10 - 1 ; var_13 ++ ) { int var_18 = var_11 [ var_13 ] + var_12 [ var_13 + 1 ] ; max = Math . max ( max , var_18 ) ; } return max ; }
201
<awangdev>256. Paint House_3.java
public int minCost(int[][] costs) { if (costs == null || costs.length == 0) return 0; int n = costs.length, m = costs[0].length; int[][] dp = new int[2][m]; for (int i = 1; i <= n; i++) { int curr = i % 2, last = (i - 1) % 2; for (int j = 0; j < m; j++) { dp[curr][j] = Integer.MAX_VALUE; for (int k = 0; k < m; k++) { if (j == k) continue; dp[curr][j] = Math.min(dp[curr][j], dp[last][k] + costs[i - 1][j]); } } } int min = Integer.MAX_VALUE; for (int j = 0; j < m; j++) min = Math.min(min, dp[n%2][j]); return min; }
public int sample_funcname ( int [ ] [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length , var_5 = var_0 [ 0 ] . length ; int [ ] [ ] var_7 = new int [ 2 ] [ var_5 ] ; for ( int var_9 = 1 ; var_9 <= var_4 ; var_9 ++ ) { int var_10 = var_9 % 2 , var_11 = ( var_9 - 1 ) % 2 ; for ( int var_12 = 0 ; var_12 < var_5 ; var_12 ++ ) { var_7 [ var_10 ] [ var_12 ] = Integer . MAX_VALUE ; for ( int var_15 = 0 ; var_15 < var_5 ; var_15 ++ ) { if ( var_12 == var_15 ) continue ; var_7 [ var_10 ] [ var_12 ] = Math . min ( var_7 [ var_10 ] [ var_12 ] , var_7 [ var_11 ] [ var_15 ] + var_0 [ var_9 - 1 ] [ var_12 ] ) ; } } } int min = Integer . MAX_VALUE ; for ( int var_12 = 0 ; var_12 < var_5 ; var_12 ++ ) min = Math . min ( min , var_7 [ var_4 % 2 ] [ var_12 ] ) ; return min ; }
202
<awangdev>1203. Sort Items by Groups Respecting Dependencies_2.java
private List<Integer> topoSort(Map<Integer, List<Integer>> graph, Set<Integer> set) { Map<Integer, Integer> indegree = new HashMap<>(); for (int item : set) { indegree.put(item, 0); } for (int node : graph.keySet()) { if (!set.contains(node)) continue; for (int parent : graph.get(node)) { indegree.put(parent, indegree.get(parent) + 1); } } Queue<Integer> queue = new LinkedList<>(); for (int key : indegree.keySet()) { if (indegree.get(key) == 0) queue.offer(key); } List<Integer> rst = new ArrayList<>(); while (!queue.isEmpty()) { int node = queue.poll(); rst.add(node); if (!graph.containsKey(node)) continue; for (int parent : graph.get(node)) { indegree.put(parent, indegree.get(parent) - 1); if (indegree.get(parent) == 0) queue.offer(parent); } } return rst; }
private List < Integer > var_1 ( Map < Integer , List < Integer >> var_4 , Set < Integer > var_6 ) { Map < Integer , Integer > var_8 = new HashMap < > ( ) ; for ( int var_9 : var_6 ) { var_8 . put ( var_9 , 0 ) ; } for ( int var_13 : var_4 . keySet ( ) ) { if ( ! var_6 . contains ( var_13 ) ) continue ; for ( int var_16 : var_4 . get ( var_13 ) ) { var_8 . put ( var_16 , var_8 . get ( var_16 ) + 1 ) ; } } Queue < Integer > var_20 = new LinkedList < > ( ) ; for ( int var_21 : var_8 . keySet ( ) ) { if ( var_8 . get ( var_21 ) == 0 ) var_20 . offer ( var_21 ) ; } List < Integer > var_24 = new ArrayList < > ( ) ; while ( ! var_20 . isEmpty ( ) ) { int var_13 = var_20 . poll ( ) ; var_24 . add ( var_13 ) ; if ( ! var_4 . containsKey ( var_13 ) ) continue ; for ( int var_16 : var_4 . get ( var_13 ) ) { var_8 . put ( var_16 , var_8 . get ( var_16 ) - 1 ) ; if ( var_8 . get ( var_16 ) == 0 ) var_20 . offer ( var_16 ) ; } } return var_24 ; }
203
<awangdev>Search a 2D Matrix_1.java
public boolean searchMatrix(int[][] matrix, int target) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return false; } int row = matrix.length; int col = matrix[0].length; int start = 0; int end = row * col - 1; int mid; while (start + 1 < end) { mid = start + (end - start)/2; int num = matrix[mid/col][mid%col]; if (target == num) { return true; } else if (num < target) { start = mid; } else { end = mid; } } return (matrix[start/col][start%col] == target || matrix[end/col][end%col] == target); }
public boolean var_0 ( int [ ] [ ] var_1 , int var_2 ) { if ( var_1 == null || var_1 . length == 0 || var_1 [ 0 ] . length == 0 ) { return false ; } int var_6 = var_1 . length ; int var_7 = var_1 [ 0 ] . length ; int var_8 = 0 ; int var_10 = var_6 * var_7 - 1 ; int var_11 ; while ( var_8 + 1 < var_10 ) { var_11 = var_8 + ( var_10 - var_8 ) / 2 ; int var_13 = var_1 [ var_11 / var_7 ] [ var_11 % var_7 ] ; if ( var_2 == var_13 ) { return true ; } else if ( var_13 < var_2 ) { var_8 = var_11 ; } else { var_10 = var_11 ; } } return ( var_1 [ var_8 / var_7 ] [ var_8 % var_7 ] == var_2 || var_1 [ var_10 / var_7 ] [ var_10 % var_7 ] == var_2 ) ; }
204
<awangdev>1106. Parsing A Boolean Expression_2.java
private boolean evalList(List<Boolean> list, char op) { if (op == '&') { for (boolean b : list) { if (!b) return false; } return true; } for (boolean b : list) { if (b) return true; } return false; }
private boolean var_0 ( List < Boolean > var_3 , char var_4 ) { if ( var_4 == '&' ) { for ( boolean var_6 : var_3 ) { if ( ! var_6 ) return false ; } return true ; } for ( boolean var_6 : var_3 ) { if ( var_6 ) return true ; } return false ; }
205
<awangdev>13. Roman to Integer_2.java
private int getPlainSum(String s) { int sum = 0; for (int i = 0; i < s.length(); i++) { switch(s.charAt(i)) { case 'I': sum += 1; break; case 'V': sum += 5; break; case 'X': sum += 10; break; case 'L': sum += 50; break; case 'C': sum += 100; break; case 'D': sum += 500; break; case 'M': sum += 1000; break; default: return 0; } } return sum; }
private int sample_funcname ( String var_1 ) { int var_3 = 0 ; for ( int var_4 = 0 ; var_4 < var_1 . length ( ) ; var_4 ++ ) { switch ( var_1 . charAt ( var_4 ) ) { case 'I' : var_3 += 1 ; break ; case 'V' : var_3 += 5 ; break ; case 'X' : var_3 += 10 ; break ; case 'L' : var_3 += 50 ; break ; case 'C' : var_3 += 100 ; break ; case 'D' : var_3 += 500 ; break ; case 'M' : var_3 += 1000 ; break ; default : return 0 ; } } return var_3 ; }
206
<awangdev>560. Subarray Sum Equals K_2.java
private int[] calcPreSum(int[] nums) { int[] preSum = new int[nums.length + 1]; for (int i = 1; i <= nums.length; i++) { preSum[i] += preSum[i - 1] + nums[i - 1]; } return preSum; }
private int [ ] sample_funcname ( int [ ] var_0 ) { int [ ] var_3 = new int [ var_0 . length + 1 ] ; for ( int var_4 = 1 ; var_4 <= var_0 . length ; var_4 ++ ) { var_3 [ var_4 ] += var_3 [ var_4 - 1 ] + var_0 [ var_4 - 1 ] ; } return var_3 ; }
207
<awangdev>Backpack V_3.java
public int backPackV(int[] nums, int target) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; int[] dp = new int [target + 1]; dp[0] = 1; for (int j = 1; j <= target; j++) { dp[j] = 0; } for (int i = 1; i <= n; i++) { for (int j = target; j >= 0; j--) { if (j - nums[i - 1] >= 0) { dp[j] += dp[j - nums[i - 1]]; } } } return dp[target]; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_5 = var_0 . length ; int [ ] var_7 = new int [ var_1 + 1 ] ; var_7 [ 0 ] = 1 ; for ( int var_8 = 1 ; var_8 <= var_1 ; var_8 ++ ) { var_7 [ var_8 ] = 0 ; } for ( int var_9 = 1 ; var_9 <= var_5 ; var_9 ++ ) { for ( int var_8 = var_1 ; var_8 >= 0 ; var_8 -- ) { if ( var_8 - var_0 [ var_9 - 1 ] >= 0 ) { var_7 [ var_8 ] += var_7 [ var_8 - var_0 [ var_9 - 1 ] ] ; } } } return var_7 [ var_1 ] ; }
208
<awangdev>242. Valid Anagram_2.java
private void countChars(String s, Map<Character, Integer> count, int val) { for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); count.putIfAbsent(c, 0); count.put(c, count.get(c) + val); } }
private void var_0 ( String var_2 , Map < Character , Integer > var_6 , int var_7 ) { for ( int var_9 = 0 ; var_9 < var_2 . length ( ) ; var_9 ++ ) { char var_12 = var_2 . charAt ( var_9 ) ; var_6 . putIfAbsent ( var_12 , 0 ) ; var_6 . put ( var_12 , var_6 . get ( var_12 ) + var_7 ) ; } }
209
<awangdev>345. Reverse Vowels of a String_2.java
public String reverseVowels(String s) { if (s == null || s.length() == 0) { return s; } List<Character> vowels = Arrays.asList('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'); List<Character> matches = new ArrayList<>(); for (int i = 0; i < s.length(); i++) { if (vowels.contains(s.charAt(i))) { matches.add(s.charAt(i)); } } StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char letter = s.charAt(i); if (vowels.contains(letter)) { int lastMatchIndex = matches.size() - 1; sb.append(matches.get(lastMatchIndex)); matches.remove(lastMatchIndex); } else { sb.append(letter); } } return sb.toString(); }
public String var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) { return var_2 ; } List < Character > var_20 = Arrays . asList ( 'a' , 'e' , 'i' , 'o' , 'u' , 'A' , 'E' , 'I' , 'O' , 'U' ) ; List < Character > var_22 = new ArrayList < > ( ) ; for ( int var_23 = 0 ; var_23 < var_2 . length ( ) ; var_23 ++ ) { if ( var_20 . contains ( var_2 . charAt ( var_23 ) ) ) { var_22 . add ( var_2 . charAt ( var_23 ) ) ; } } StringBuffer var_28 = new StringBuffer ( ) ; for ( int var_23 = 0 ; var_23 < var_2 . length ( ) ; var_23 ++ ) { char var_29 = var_2 . charAt ( var_23 ) ; if ( var_20 . contains ( var_29 ) ) { int var_32 = var_22 . size ( ) - 1 ; var_28 . append ( var_22 . get ( var_32 ) ) ; var_22 . remove ( var_32 ) ; } else { var_28 . append ( var_29 ) ; } } return var_28 . toString ( ) ; }
210
<awangdev>Wiggle Sort_2.java
private void swap(int[] nums, int x, int y) { int temp = nums[x]; nums[x] = nums[y]; nums[y] = temp; }
private void var_0 ( int [ ] var_1 , int var_2 , int var_3 ) { int var_4 = var_1 [ var_2 ] ; var_1 [ var_2 ] = var_1 [ var_3 ] ; var_1 [ var_3 ] = var_4 ; }
211
<awangdev>Redundant Connection_1.java
private boolean hasCycle(Map<Integer, Set<Integer>> graph, int curr, int target, int pre) { if (graph.get(curr).contains(target)) return true; for (int num : graph.get(curr)) { if (num == pre) continue; if (hasCycle(graph, num, target, curr)) return true; } return false; }
private boolean sample_funcname ( Map < Integer , Set < Integer >> graph , int curr , int target , int pre ) { if ( graph . get ( curr ) . contains ( target ) ) return true ; for ( int num : graph . get ( curr ) ) { if ( num == pre ) continue ; if ( hasCycle ( graph , num , target , curr ) ) return true ; } return false ; }
212
<awangdev>953. Verifying an Alien Dictionary_1.java
private boolean compareStr(String s1, String s2, int[] orderIndex) { if (s1.indexOf(s2) >= 0) return false; int size = Math.min(s1.length(), s2.length()); for (int i = 0; i < size; i++) { int c1 = s1.charAt(i), c2 = s2.charAt(i); if (orderIndex[c1] == orderIndex[c2]) continue; return orderIndex[c1] < orderIndex[c2]; } return true; }
private boolean var_0 ( String var_2 , String var_3 , int [ ] var_4 ) { if ( var_2 . indexOf ( var_3 ) >= 0 ) return false ; int var_10 = Math . min ( var_2 . length ( ) , var_3 . length ( ) ) ; for ( int var_11 = 0 ; var_11 < var_10 ; var_11 ++ ) { int var_13 = var_2 . charAt ( var_11 ) , var_14 = var_3 . charAt ( var_11 ) ; if ( var_4 [ var_13 ] == var_4 [ var_14 ] ) continue ; return var_4 [ var_13 ] < var_4 [ var_14 ] ; } return true ; }
213
<awangdev>287. Find the Duplicate Number_1.java
public int findDuplicate(int[] nums) { int slow = nums[0], fast = nums[nums[0]]; while (slow != fast) { slow = nums[slow]; fast = nums[nums[fast]]; } int finder = 0; while (slow != finder) { slow = nums[slow]; finder = nums[finder]; } return slow; }
public int sample_funcname ( int [ ] var_0 ) { int var_2 = var_0 [ 0 ] , var_3 = var_0 [ var_0 [ 0 ] ] ; while ( var_2 != var_3 ) { var_2 = var_0 [ var_2 ] ; var_3 = var_0 [ var_0 [ var_3 ] ] ; } int var_4 = 0 ; while ( var_2 != var_4 ) { var_2 = var_0 [ var_2 ] ; var_4 = var_0 [ var_4 ] ; } return var_2 ; }
214
<awangdev>Backpack II_7.java
public int backPackII(int m, int[] A, int V[]) { if (A == null || V == null || A.length == 0 || V.length == 0 || A.length != V.length || m <= 0) { return 0; } int[][] dp = new int[A.length + 1][m + 1]; dp[0][0] = 0; for (int i = 1; i <= A.length; i++) { for (int j = 0; j <= m; j++) { if (j - A[i - 1] >= 0) { dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - A[i - 1]] + V[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } } } return dp[A.length][m]; }
public int sample_funcname ( int var_0 , int [ ] var_1 , int var_2 [ ] ) { if ( var_1 == null || var_2 == null || var_1 . length == 0 || var_2 . length == 0 || var_1 . length != var_2 . length || var_0 <= 0 ) { return 0 ; } int [ ] [ ] var_7 = new int [ var_1 . length + 1 ] [ var_0 + 1 ] ; var_7 [ 0 ] [ 0 ] = 0 ; for ( int var_8 = 1 ; var_8 <= var_1 . length ; var_8 ++ ) { for ( int var_9 = 0 ; var_9 <= var_0 ; var_9 ++ ) { if ( var_9 - var_1 [ var_8 - 1 ] >= 0 ) { var_7 [ var_8 ] [ var_9 ] = Math . max ( var_7 [ var_8 - 1 ] [ var_9 ] , var_7 [ var_8 - 1 ] [ var_9 - var_1 [ var_8 - 1 ] ] + var_2 [ var_8 - 1 ] ) ; } else { var_7 [ var_8 ] [ var_9 ] = var_7 [ var_8 - 1 ] [ var_9 ] ; } } } return var_7 [ var_1 . length ] [ var_0 ] ; }
215
<awangdev>Coins in a Line III_1.java
public boolean firstWillWin(int[] values) { if (values == null || values.length == 0) { return false; } int n = values.length; int[][] dp = new int[n][n]; for (int i = 0; i < n; i++) { dp[i][i] = values[i]; } for (int len = 2; len <= n; len++) { for (int i = 0; i <= n - len; i++) { int j = len + i - 1; dp[i][j] = Math.max(values[i] - dp[i + 1][j], values[j] - dp[i][j - 1]); } } return dp[0][n - 1] >= 0; }
public boolean var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return false ; } int var_5 = var_1 . length ; int [ ] [ ] var_6 = new int [ var_5 ] [ var_5 ] ; for ( int var_7 = 0 ; var_7 < var_5 ; var_7 ++ ) { var_6 [ var_7 ] [ var_7 ] = var_1 [ var_7 ] ; } for ( int var_9 = 2 ; var_9 <= var_5 ; var_9 ++ ) { for ( int var_7 = 0 ; var_7 <= var_5 - var_9 ; var_7 ++ ) { int var_11 = var_9 + var_7 - 1 ; var_6 [ var_7 ] [ var_11 ] = Math . max ( var_1 [ var_7 ] - var_6 [ var_7 + 1 ] [ var_11 ] , var_1 [ var_11 ] - var_6 [ var_7 ] [ var_11 - 1 ] ) ; } } return var_6 [ 0 ] [ var_5 - 1 ] >= 0 ; }
216
<awangdev>47. Permutations II_1.java
private void dfs(List<List<Integer>> rst, List list, Queue<Integer> queue) { if (queue.isEmpty()) { rst.add(new ArrayList<>(list)); return; } int size = queue.size(); Integer last = null; while (size-- > 0) { int val = queue.poll(); if (last != null && last == val) { queue.offer(val); continue; } list.add(val); dfs(rst, list, queue); list.remove(list.size() - 1); queue.offer(val); last = val; } }
private void sample_funcname ( List < List < Integer >> rst , List list , Queue < Integer > queue ) { if ( queue . isEmpty ( ) ) { rst . add ( new ArrayList < > ( list ) ) ; return ; } int size = queue . size ( ) ; Integer last = null ; while ( size -- > 0 ) { int val = queue . poll ( ) ; if ( last != null && last == val ) { queue . offer ( val ) ; continue ; } list . add ( val ) ; dfs ( rst , list , queue ) ; list . remove ( list . size ( ) - 1 ) ; queue . offer ( val ) ; last = val ; } }
217
<awangdev>46. Permutations_1.java
private void dfs(List<List<Integer>> rst, List<Integer> list, Queue<Integer> queue) { if (queue.isEmpty()) { rst.add(new ArrayList<>(list)); return; } int size = queue.size(); while (size-- > 0) { int val = queue.poll(); list.add(val); dfs(rst, list, queue); list.remove(list.size() - 1); queue.offer(val); } }
private void sample_funcname ( List < List < Integer >> rst , List < Integer > list , Queue < Integer > queue ) { if ( queue . isEmpty ( ) ) { rst . add ( new ArrayList < > ( list ) ) ; return ; } int size = queue . size ( ) ; while ( size -- > 0 ) { int val = queue . poll ( ) ; list . add ( val ) ; dfs ( rst , list , queue ) ; list . remove ( list . size ( ) - 1 ) ; queue . offer ( val ) ; } }
218
<awangdev>14. Longest Common Prefix_1.java
public String longestCommonPrefix(String[] strs) { if (strs == null || strs.length == 0) { return ""; } Arrays.sort(strs); String head = strs[0]; String tail = strs[strs.length - 1]; int size = head.length() < tail.length() ? head.length() : tail.length(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < size; i++) { if (head.charAt(i) != tail.charAt(i)) { break; } sb.append(head.charAt(i)); } return sb.toString(); }
public String var_0 ( String [ ] var_2 ) { if ( var_2 == null || var_2 . length == 0 ) { return "" ; } Arrays . sort ( var_2 ) ; String var_9 = var_2 [ 0 ] ; String var_11 = var_2 [ var_2 . length - 1 ] ; int var_12 = var_9 . length ( ) < var_11 . length ( ) ? var_9 . length ( ) : var_11 . length ( ) ; StringBuffer var_14 = new StringBuffer ( ) ; for ( int var_15 = 0 ; var_15 < var_12 ; var_15 ++ ) { if ( var_9 . charAt ( var_15 ) != var_11 . charAt ( var_15 ) ) { break ; } var_14 . append ( var_9 . charAt ( var_15 ) ) ; } return var_14 . toString ( ) ; }
219
<awangdev>Jump Game II_2.java
public int jump(int[] nums) { if (nums == null || nums.length == 0) return 0; int n = nums.length; int[] dp = new int[n]; dp[0] = 0; for (int i = 1; i < n; i++) { dp[i] = Integer.MAX_VALUE; for (int j = 0; j < i; j++) { if (j + nums[j] >= i) dp[i] = Math.min(dp[i], dp[j] + 1); } } return dp[n - 1]; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length ; int [ ] var_5 = new int [ var_4 ] ; var_5 [ 0 ] = 0 ; for ( int var_7 = 1 ; var_7 < var_4 ; var_7 ++ ) { var_5 [ var_7 ] = Integer . MAX_VALUE ; for ( int var_10 = 0 ; var_10 < var_7 ; var_10 ++ ) { if ( var_10 + var_0 [ var_10 ] >= var_7 ) var_5 [ var_7 ] = Math . min ( var_5 [ var_7 ] , var_5 [ var_10 ] + 1 ) ; } } return var_5 [ var_4 - 1 ] ; }
220
<awangdev>1306. Jump Game III_1.java
private void add(Queue<Integer> queue, int[] arr, int start) { int left = start - arr[start], right = start + arr[start]; if (left >= 0) queue.offer(left); if (right < arr.length) queue.offer(right); }
private void var_0 ( Queue < Integer > var_3 , int [ ] var_4 , int var_5 ) { int var_6 = var_5 - var_4 [ var_5 ] , var_7 = var_5 + var_4 [ var_5 ] ; if ( var_6 >= 0 ) var_3 . offer ( var_6 ) ; if ( var_7 < var_4 . length ) var_3 . offer ( var_7 ) ; }
221
<awangdev>Word Pattern_1.java
public boolean wordPattern(String pattern, String str) { if (pattern == null || pattern.length() == 0 || str == null || str.length() == 0) { return false; } String[] strArr = str.split(" "); if (pattern.length() != strArr.length) { return false; } HashMap<Character, String> map = new HashMap<Character, String>(); for (int i = 0; i < pattern.length(); i++) { char c = pattern.charAt(i); String s = strArr[i]; if (!map.containsKey(c)) { if (map.containsValue(s)) { return false; } map.put(c, s); } else if (!map.get(c).equals(s)) { return false; } } return true; }
public boolean var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_2 . length ( ) == 0 || var_3 == null || var_3 . length ( ) == 0 ) { return false ; } String [ ] var_9 = var_3 . split ( " " ) ; if ( var_2 . length ( ) != var_9 . length ) { return false ; } HashMap < Character , String > var_12 = new HashMap < Character , String > ( ) ; for ( int var_13 = 0 ; var_13 < var_2 . length ( ) ; var_13 ++ ) { char var_15 = var_2 . charAt ( var_13 ) ; String var_16 = var_9 [ var_13 ] ; if ( ! var_12 . containsKey ( var_15 ) ) { if ( var_12 . containsValue ( var_16 ) ) { return false ; } var_12 . put ( var_15 , var_16 ) ; } else if ( ! var_12 . get ( var_15 ) . equals ( var_16 ) ) { return false ; } } return true ; }
222
<awangdev>121. Best Time to Buy and Sell Stock_1.java
public int maxProfit(int[] prices) { if (prices == null || prices.length <= 1) return 0; int profit = 0, n = prices.length; int[] min = new int[n]; min[0] = prices[0]; for (int i = 1; i < n; i++) { min[i] = Math.min(min[i - 1], prices[i]); profit = Math.max(profit, prices[i] - min[i]); } return profit; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length <= 1 ) return 0 ; int var_5 = 0 , var_6 = var_0 . length ; int [ ] min = new int [ var_6 ] ; min [ 0 ] = var_0 [ 0 ] ; for ( int var_8 = 1 ; var_8 < var_6 ; var_8 ++ ) { min [ var_8 ] = Math . min ( min [ var_8 - 1 ] , var_0 [ var_8 ] ) ; var_5 = Math . max ( var_5 , var_0 [ var_8 ] - min [ var_8 ] ) ; } return var_5 ; }
223
<awangdev>200. Number of Islands_4.java
private boolean validate(char[][] grid, int x, int y) { return x < 0 || x >= grid.length || y < 0 || y >= grid[0].length || grid[x][y] == '0'; }
private boolean var_0 ( char [ ] [ ] var_1 , int var_2 , int var_3 ) { return var_2 < 0 || var_2 >= var_1 . length || var_3 < 0 || var_3 >= var_1 [ 0 ] . length || var_1 [ var_2 ] [ var_3 ] == '0' ; }
224
<awangdev>One Edit Distance_2.java
public boolean isOneEditDistance(String s, String t) { if (s == null || t == null || s.equals(t) || Math.abs(s.length() - t.length()) > 1) { return false; } int size = s.length() > t.length() ? t.length() : s.length(); for (int i = 0; i < size; i++) { if (s.charAt(i) != t.charAt(i)) { if (s.substring(i + 1).equals(t.substring(i)) || s.substring(i).equals(t.substring(i + 1))) { return true; } return s.substring(i + 1).equals(t.substring(i + 1)); } } return true; }
public boolean var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_3 == null || var_2 . equals ( var_3 ) || Math . abs ( var_2 . length ( ) - var_3 . length ( ) ) > 1 ) { return false ; } int var_10 = var_2 . length ( ) > var_3 . length ( ) ? var_3 . length ( ) : var_2 . length ( ) ; for ( int var_12 = 0 ; var_12 < var_10 ; var_12 ++ ) { if ( var_2 . charAt ( var_12 ) != var_3 . charAt ( var_12 ) ) { if ( var_2 . substring ( var_12 + 1 ) . equals ( var_3 . substring ( var_12 ) ) || var_2 . substring ( var_12 ) . equals ( var_3 . substring ( var_12 + 1 ) ) ) { return true ; } return var_2 . substring ( var_12 + 1 ) . equals ( var_3 . substring ( var_12 + 1 ) ) ; } } return true ; }
225
<awangdev>40. Combination Sum II_2.java
private boolean validate(int[] candidates, int target) { return candidates == null || candidates.length == 0 || target <= 0; }
private boolean var_0 ( int [ ] var_1 , int var_2 ) { return var_1 == null || var_1 . length == 0 || var_2 <= 0 ; }
226
<awangdev>509. Fibonacci Number_2.java
public int fibonacci(int n) { if (n <= 1) { return 0; } int[] fib = new int[n]; fib[0] = 0; fib[1] = 1; for (int i = 2; i < n; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } return fib[n - 1]; }
public int sample_funcname ( int var_0 ) { if ( var_0 <= 1 ) { return 0 ; } int [ ] var_3 = new int [ var_0 ] ; var_3 [ 0 ] = 0 ; var_3 [ 1 ] = 1 ; for ( int var_5 = 2 ; var_5 < var_0 ; var_5 ++ ) { var_3 [ var_5 ] = var_3 [ var_5 - 1 ] + var_3 [ var_5 - 2 ] ; } return var_3 [ var_0 - 1 ] ; }
227
<awangdev>55. Jump Game_3.java
public boolean canJump(int[] nums) { if (nums == null || nums.length == 0) return true; int n = nums.length; boolean[] dp = new boolean[n]; dp[0] = true; for (int i = 1; i < n; i++) { dp[i] = false; for (int j = 0; j < i; j++) { if (dp[j] && j + nums[j] >= i) { dp[i] = true; break; } } } return dp[n - 1]; }
public boolean var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) return true ; int var_5 = var_1 . length ; boolean [ ] var_7 = new boolean [ var_5 ] ; var_7 [ 0 ] = true ; for ( int var_9 = 1 ; var_9 < var_5 ; var_9 ++ ) { var_7 [ var_9 ] = false ; for ( int var_10 = 0 ; var_10 < var_9 ; var_10 ++ ) { if ( var_7 [ var_10 ] && var_10 + var_1 [ var_10 ] >= var_9 ) { var_7 [ var_9 ] = true ; break ; } } } return var_7 [ var_5 - 1 ] ; }
228
<awangdev>Find Peak Element_3.java
public int findPeakElement(int[] nums) { if (nums == null || nums.length <= 1) { return 0; } int n = nums.length; int start = 0; int end = nums.length - 1; int mid = 0; while (start <= end) { mid = start + (end - start) / 2; if ((mid - 1 < 0 || nums[mid] > nums[mid - 1]) && (mid + 1 >= n || nums[mid] > nums[mid + 1])) { return mid; } else if (mid - 1 >= 0 && nums[mid] < nums[mid - 1]) { end = mid - 1; } else { start = mid + 1; } } return mid; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length <= 1 ) { return 0 ; } int var_5 = var_0 . length ; int var_6 = 0 ; int var_7 = var_0 . length - 1 ; int var_8 = 0 ; while ( var_6 <= var_7 ) { var_8 = var_6 + ( var_7 - var_6 ) / 2 ; if ( ( var_8 - 1 < 0 || var_0 [ var_8 ] > var_0 [ var_8 - 1 ] ) && ( var_8 + 1 >= var_5 || var_0 [ var_8 ] > var_0 [ var_8 + 1 ] ) ) { return var_8 ; } else if ( var_8 - 1 >= 0 && var_0 [ var_8 ] < var_0 [ var_8 - 1 ] ) { var_7 = var_8 - 1 ; } else { var_6 = var_8 + 1 ; } } return var_8 ; }
229
<awangdev>Minimum Subarray_1.java
public int minSubArray(List<Integer> nums) { if (nums == null || nums.size() == 0) return Integer.MAX_VALUE; int preMinSum = 0, min = Integer.MAX_VALUE; for (int num : nums) { preMinSum = Math.min(num, preMinSum + num); min = Math.min(min, preMinSum); } return min; }
public int sample_funcname ( List < Integer > var_2 ) { if ( var_2 == null || var_2 . size ( ) == 0 ) return Integer . MAX_VALUE ; int var_7 = 0 , min = Integer . MAX_VALUE ; for ( int var_9 : var_2 ) { var_7 = Math . min ( var_9 , var_7 + var_9 ) ; min = Math . min ( min , var_7 ) ; } return min ; }
230
<awangdev>One Edit Distance_3.java
public boolean isOneEditDistance(String s, String t) { if (s == null || t == null) { return false; } else if (Math.abs(s.length() - t.length()) > 1 || s.equals(t)) { return false; } int leng = s.length() > t.length() ? t.length() : s.length(); for (int i = 0; i < leng; i++) { String ss = s; String tt = t; if (s.charAt(i) != t.charAt(i)) { tt = t.substring(i + 1); ss = s.substring(i); if (tt.equals(ss)) { return true; } tt = t.substring(i); ss = s.substring(i + 1); if (tt.equals(ss)) { return true; } ss = s.substring(0, i) + s.substring(i + 1); tt = t.substring(0, i) + t.substring(i + 1); return ss.equals(tt); } } return true; }
public boolean var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_3 == null ) { return false ; } else if ( Math . abs ( var_2 . length ( ) - var_3 . length ( ) ) > 1 || var_2 . equals ( var_3 ) ) { return false ; } int var_10 = var_2 . length ( ) > var_3 . length ( ) ? var_3 . length ( ) : var_2 . length ( ) ; for ( int var_12 = 0 ; var_12 < var_10 ; var_12 ++ ) { String var_13 = var_2 ; String var_14 = var_3 ; if ( var_2 . charAt ( var_12 ) != var_3 . charAt ( var_12 ) ) { var_14 = var_3 . substring ( var_12 + 1 ) ; var_13 = var_2 . substring ( var_12 ) ; if ( var_14 . equals ( var_13 ) ) { return true ; } var_14 = var_3 . substring ( var_12 ) ; var_13 = var_2 . substring ( var_12 + 1 ) ; if ( var_14 . equals ( var_13 ) ) { return true ; } var_13 = var_2 . substring ( 0 , var_12 ) + var_2 . substring ( var_12 + 1 ) ; var_14 = var_3 . substring ( 0 , var_12 ) + var_3 . substring ( var_12 + 1 ) ; return var_13 . equals ( var_14 ) ; } } return true ; }
231
<awangdev>Maximum Average Subarray I_1.java
public double findMaxAverage(int[] nums, int k) { if (nums == null || nums.length == 0) { return 0; } double sum = 0; for (int i = 0; i < k; i++) { sum += nums[i]; } double max = sum; for (int i = k; i < nums.length; i++) { max = Math.max(sum, max); sum = sum - nums[i - k] + nums[i]; } max = Math.max(sum, max); return max / k; }
public double sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } double var_5 = 0 ; for ( int var_6 = 0 ; var_6 < var_1 ; var_6 ++ ) { var_5 += var_0 [ var_6 ] ; } double max = var_5 ; for ( int var_6 = var_1 ; var_6 < var_0 . length ; var_6 ++ ) { max = Math . max ( var_5 , max ) ; var_5 = var_5 - var_0 [ var_6 - var_1 ] + var_0 [ var_6 ] ; } max = Math . max ( var_5 , max ) ; return max / var_1 ; }
232
<awangdev>40. Combination Sum II_3.java
private void dfs(List<List<Integer>> result, List<Integer> list, int[] candidates, int index, int target) { for (int i = index; i < candidates.length; i++) { if (i > index && candidates[i] == candidates[i - 1]) continue; int value = candidates[i]; list.add(value); if (target == value) result.add(new ArrayList<>(list)); else if (target - value > 0) dfs(result, list, candidates, i + 1, target - value); list.remove(list.size() - 1); } }
private void sample_funcname ( List < List < Integer >> result , List < Integer > list , int [ ] candidates , int index , int target ) { for ( int i = index ; i < candidates . length ; i ++ ) { if ( i > index && candidates [ i ] == candidates [ i - 1 ] ) continue ; int value = candidates [ i ] ; list . add ( value ) ; if ( target == value ) result . add ( new ArrayList < > ( list ) ) ; else if ( target - value > 0 ) dfs ( result , list , candidates , i + 1 , target - value ) ; list . remove ( list . size ( ) - 1 ) ; } }
233
<awangdev>55. Jump Game_2.java
public boolean canJump(int[] nums) { if (nums == null || nums.length == 0) return true; int n = nums.length, lastPos = n - 1; for (int i = lastPos; i >= 0; i--) { if (i + nums[i] >= lastPos) lastPos = i; } return lastPos == 0; }
public boolean var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) return true ; int var_5 = var_1 . length , var_7 = var_5 - 1 ; for ( int var_8 = var_7 ; var_8 >= 0 ; var_8 -- ) { if ( var_8 + var_1 [ var_8 ] >= var_7 ) var_7 = var_8 ; } return var_7 == 0 ; }
234
<awangdev>Find Peak Element_2.java
public int findPeakElement(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; int start = 0; int end = n - 1; while (start + 1 < end) { int mid = (start + end) >> 1; if (nums[mid] > nums[mid - 1] && nums[mid] > nums[mid + 1]) { return mid; } else if (nums[mid] > nums[mid - 1]) { start = mid; } else { end = mid; } } return nums[start] > nums[end] ? start : end; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = var_0 . length ; int var_5 = 0 ; int var_7 = var_4 - 1 ; while ( var_5 + 1 < var_7 ) { int var_8 = ( var_5 + var_7 ) >> 1 ; if ( var_0 [ var_8 ] > var_0 [ var_8 - 1 ] && var_0 [ var_8 ] > var_0 [ var_8 + 1 ] ) { return var_8 ; } else if ( var_0 [ var_8 ] > var_0 [ var_8 - 1 ] ) { var_5 = var_8 ; } else { var_7 = var_8 ; } } return var_0 [ var_5 ] > var_0 [ var_7 ] ? var_5 : var_7 ; }
235
<awangdev>509. Fibonacci Number_3.java
public int fibonacci(int n) { if (n <= 1) { return 0; } if (n == 2) { return 1; } return fibonacci(n - 1) + fibonacci(n - 2); }
public int sample_funcname ( int n ) { if ( n <= 1 ) { return 0 ; } if ( n == 2 ) { return 1 ; } return fibonacci ( n - 1 ) + fibonacci ( n - 2 ) ; }
236
<awangdev>Jump Game II_3.java
public int jump(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; int start = 0, end = 0, steps = 0; while (end < n - 1) { steps++; int farthest = 0; for (int i = start; i <= end; i++) { farthest = Math.max(farthest, i + nums[i]); if (farthest >= n - 1) { return steps; } } start = end + 1; end = farthest; } return 0; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = var_0 . length ; int var_5 = 0 , var_6 = 0 , var_7 = 0 ; while ( var_6 < var_4 - 1 ) { var_7 ++ ; int var_9 = 0 ; for ( int var_10 = var_5 ; var_10 <= var_6 ; var_10 ++ ) { var_9 = Math . max ( var_9 , var_10 + var_0 [ var_10 ] ) ; if ( var_9 >= var_4 - 1 ) { return var_7 ; } } var_5 = var_6 + 1 ; var_6 = var_9 ; } return 0 ; }
237
<awangdev>Excel Sheet Column Number_1.java
public int titleToNumber(String s) { if (s == null || s.length() == 0) { return 0; } int count = 0; for (char c : s.toCharArray()) { int digit = c - 'A' + 1; count = count * 26 + digit; } return count; }
public int sample_funcname ( String var_1 ) { if ( var_1 == null || var_1 . length ( ) == 0 ) { return 0 ; } int var_5 = 0 ; for ( char var_7 : var_1 . toCharArray ( ) ) { int var_10 = var_7 - 'A' + 1 ; var_5 = var_5 * 26 + var_10 ; } return var_5 ; }
238
<awangdev>200. Number of Islands_5.java
private boolean validate(char[][] grid, int x, int y) { return x >= 0 && x < grid.length && y >= 0 && y < grid[0].length && grid[x][y] == '1'; }
private boolean var_0 ( char [ ] [ ] var_1 , int var_2 , int var_3 ) { return var_2 >= 0 && var_2 < var_1 . length && var_3 >= 0 && var_3 < var_1 [ 0 ] . length && var_1 [ var_2 ] [ var_3 ] == '1' ; }
239
<awangdev>53. Maximum Subarray_1.java
public int maxSubArray(int[] nums) { if (nums == null || nums.length == 0) return Integer.MIN_VALUE; int preMaxSum = 0, max = Integer.MIN_VALUE; for (int num : nums) { preMaxSum = Math.max(num, preMaxSum + num); max = Math.max(max, preMaxSum); } return max; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return Integer . MIN_VALUE ; int var_6 = 0 , max = Integer . MIN_VALUE ; for ( int var_8 : var_0 ) { var_6 = Math . max ( var_8 , var_6 + var_8 ) ; max = Math . max ( max , var_6 ) ; } return max ; }
240
<awangdev>523. Continuous Subarray Sum_1.java
public boolean checkSubarraySum(int[] nums, int k) { k = k == 0 ? Integer.MAX_VALUE : Math.abs(k); if (nums.length / 2 > k) return true; Set<Integer> set = new HashSet<>(); int lastMod = 0; for (int num : nums) { int mod = (lastMod + num) % k; if (set.contains(mod)) return true; set.add(lastMod); lastMod = mod; } return false; }
public boolean var_0 ( int [ ] var_1 , int var_2 ) { var_2 = var_2 == 0 ? Integer . MAX_VALUE : Math . abs ( var_2 ) ; if ( var_1 . length / 2 > var_2 ) return true ; Set < Integer > var_12 = new HashSet < > ( ) ; int var_13 = 0 ; for ( int var_14 : var_1 ) { int var_15 = ( var_13 + var_14 ) % var_2 ; if ( var_12 . contains ( var_15 ) ) return true ; var_12 . add ( var_13 ) ; var_13 = var_15 ; } return false ; }
241
<awangdev>1060. Missing Element in Sorted Array_1.java
public int missingElement(int[] nums, int k) { int start = 0, end = nums.length - 1; int count = nums[end] - nums[0] - end; if (count < k) { return nums[end] + k - count; } while (start + 1 < end) { int mid = start + (end - start) / 2; count = nums[mid] - nums[0] - mid; if (count >= k) end = mid; else start = mid; } count = nums[start] - nums[0] - start; return nums[start] + k - count; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { int var_3 = 0 , var_6 = var_0 . length - 1 ; int var_7 = var_0 [ var_6 ] - var_0 [ 0 ] - var_6 ; if ( var_7 < var_1 ) { return var_0 [ var_6 ] + var_1 - var_7 ; } while ( var_3 + 1 < var_6 ) { int var_9 = var_3 + ( var_6 - var_3 ) / 2 ; var_7 = var_0 [ var_9 ] - var_0 [ 0 ] - var_9 ; if ( var_7 >= var_1 ) var_6 = var_9 ; else var_3 = var_9 ; } var_7 = var_0 [ var_3 ] - var_0 [ 0 ] - var_3 ; return var_0 [ var_3 ] + var_1 - var_7 ; }
242
<awangdev>315. Count of Smaller Numbers After Self_2.java
private int[] findRange(int[] nums) { int diff = 0, min = Integer.MAX_VALUE, max = Integer.MIN_VALUE; for (int num : nums) { min = Math.min(min, num); max = Math.max(max, num); } if (min < 0) { diff = Math.abs(min); max += diff; min += diff; } return new int[]{min, max, diff}; }
private int [ ] sample_funcname ( int [ ] var_0 ) { int var_2 = 0 , min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ; for ( int var_8 : var_0 ) { min = Math . min ( min , var_8 ) ; max = Math . max ( max , var_8 ) ; } if ( min < 0 ) { var_2 = Math . abs ( min ) ; max += var_2 ; min += var_2 ; } return new int [ ] { min , max , var_2 }; }
243
<awangdev>Burst Balloons_1.java
public int maxCoins(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; int[] values = new int[n + 2]; values[0] = 1; values[n + 1] = 1; for (int i = 1; i <= n; i++) { values[i] = nums[i - 1]; } n = values.length; int[][] dp = new int[n][n]; for (int len = 3; len <= n; len++) { for (int i = 0; i <= n - len; i++) { int j = len + i - 1; for (int k = i + 1; k < j; k++) { dp[i][j] = Math.max(dp[i][j], dp[i][k] + dp[k][j] + values[i] * values[k] * values[j]); } } } return dp[0][n - 1]; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = var_0 . length ; int [ ] var_6 = new int [ var_4 + 2 ] ; var_6 [ 0 ] = 1 ; var_6 [ var_4 + 1 ] = 1 ; for ( int var_8 = 1 ; var_8 <= var_4 ; var_8 ++ ) { var_6 [ var_8 ] = var_0 [ var_8 - 1 ] ; } var_4 = var_6 . length ; int [ ] [ ] var_9 = new int [ var_4 ] [ var_4 ] ; for ( int var_11 = 3 ; var_11 <= var_4 ; var_11 ++ ) { for ( int var_8 = 0 ; var_8 <= var_4 - var_11 ; var_8 ++ ) { int var_12 = var_11 + var_8 - 1 ; for ( int var_13 = var_8 + 1 ; var_13 < var_12 ; var_13 ++ ) { var_9 [ var_8 ] [ var_12 ] = Math . max ( var_9 [ var_8 ] [ var_12 ] , var_9 [ var_8 ] [ var_13 ] + var_9 [ var_13 ] [ var_12 ] + var_6 [ var_8 ] * var_6 [ var_13 ] * var_6 [ var_12 ] ) ; } } } return var_9 [ 0 ] [ var_4 - 1 ] ; }
244
<awangdev>1094. Car Pooling_2.java
private PriorityQueue<int[]> buildQueue(int[][] trips) { PriorityQueue<int[]> queue = new PriorityQueue<>(Comparator.comparing(p -> p[0])); for (int[] trip : trips) { queue.offer(new int[]{trip[1], trip[0]}); queue.offer(new int[]{trip[2], -trip[0]}); } return queue; }
private PriorityQueue < int [ ] > var_0 ( int [ ] [ ] var_1 ) { PriorityQueue < int [ ] > var_7 = new PriorityQueue < > ( Comparator . comparing ( var_3 -> var_3 [ 0 ] ) ) ; for ( int [ ] var_8 : var_1 ) { var_7 . offer ( new int [ ] { var_8 [ 1 ] , var_8 [ 0 ] } ) ; var_7 . offer ( new int [ ] { var_8 [ 2 ] , - var_8 [ 0 ] } ) ; } return var_7 ; }
245
<awangdev>Wiggle Sort_3.java
public void swap(int[] nums, int x, int y) { int temp = nums[x]; nums[x] = nums[y]; nums[y] = temp; }
public void var_0 ( int [ ] var_1 , int var_2 , int var_3 ) { int var_4 = var_1 [ var_2 ] ; var_1 [ var_2 ] = var_1 [ var_3 ] ; var_1 [ var_3 ] = var_4 ; }
246
<awangdev>[lint]. 3 Sum Closest_1.java
public int threeSumClosest(int[] nums, int target) { if (nums == null || nums.length < 3) { return 0; } Arrays.sort(nums); long result = nums[0] + nums[1] + nums[2]; for (int i = 0; i < nums.length - 2; i++) { int start = i + 1; int end = nums.length - 1; while (start < end) { long sum = nums[start] + nums[end] + nums[i]; if (sum > target) { end--; } else { start++; } result = Math.abs(sum - target) < Math.abs(result - target) ? sum : result; } } return (int)result; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length < 3 ) { return 0 ; } Arrays . sort ( var_0 ) ; long var_10 = var_0 [ 0 ] + var_0 [ 1 ] + var_0 [ 2 ] ; for ( int var_11 = 0 ; var_11 < var_0 . length - 2 ; var_11 ++ ) { int var_12 = var_11 + 1 ; int var_13 = var_0 . length - 1 ; while ( var_12 < var_13 ) { long var_14 = var_0 [ var_12 ] + var_0 [ var_13 ] + var_0 [ var_11 ] ; if ( var_14 > var_1 ) { var_13 -- ; } else { var_12 ++ ; } var_10 = Math . abs ( var_14 - var_1 ) < Math . abs ( var_10 - var_1 ) ? var_14 : var_10 ; } } return ( int ) var_10 ; }
247
<awangdev>Two Strings Are Anagrams_2.java
public boolean isAnagram(String s, String t) { if (s == null || t == null || s.length() != t.length()) { return false; } if (s.equals(t)) { return true; } HashMap<String, Integer> map = new HashMap<String, Integer>(); for (int i = 0; i < s.length(); i++) { String ss = s.substring(i, i + 1); String tt = t.substring(i, i + 1); if (!map.containsKey(ss)) { map.put(ss, 0); } map.put(ss, map.get(ss) + 1); if (!map.containsKey(tt)) { map.put(tt, 0); } map.put(tt, map.get(tt) - 1); } for (Map.Entry<String, Integer> entry : map.entrySet()) { if (entry.getValue() != 0) { return false; } } return true; }
public boolean var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_3 == null || var_2 . length ( ) != var_3 . length ( ) ) { return false ; } if ( var_2 . equals ( var_3 ) ) { return true ; } HashMap < String , Integer > var_9 = new HashMap < String , Integer > ( ) ; for ( int var_11 = 0 ; var_11 < var_2 . length ( ) ; var_11 ++ ) { String var_14 = var_2 . substring ( var_11 , var_11 + 1 ) ; String var_15 = var_3 . substring ( var_11 , var_11 + 1 ) ; if ( ! var_9 . containsKey ( var_14 ) ) { var_9 . put ( var_14 , 0 ) ; } var_9 . put ( var_14 , var_9 . get ( var_14 ) + 1 ) ; if ( ! var_9 . containsKey ( var_15 ) ) { var_9 . put ( var_15 , 0 ) ; } var_9 . put ( var_15 , var_9 . get ( var_15 ) - 1 ) ; } for ( Map . Entry < String , Integer > var_20 : var_9 . entrySet ( ) ) { if ( var_20 . getValue ( ) != 0 ) { return false ; } } return true ; }
248
<awangdev>33. Search in Rotated Sorted Array_1.java
public int search(int[] nums, int target) { if (nums == null || nums.length == 0) return -1; int start = 0, end = nums.length - 1; while (start + 1 < end) { int mid = start + (end - start) / 2; if (nums[mid] == target) return mid; if (nums[start] < nums[mid]) { if (nums[start] <= target && target <= nums[mid]) end = mid; else start = mid; } else { if (nums[mid] <= target && target <= nums[end]) start = mid; else end = mid; } } if (nums[start] == target) return start; if (nums[end] == target) return end; return -1; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) return - 1 ; int var_6 = 0 , var_7 = var_0 . length - 1 ; while ( var_6 + 1 < var_7 ) { int var_9 = var_6 + ( var_7 - var_6 ) / 2 ; if ( var_0 [ var_9 ] == var_1 ) return var_9 ; if ( var_0 [ var_6 ] < var_0 [ var_9 ] ) { if ( var_0 [ var_6 ] <= var_1 && var_1 <= var_0 [ var_9 ] ) var_7 = var_9 ; else var_6 = var_9 ; } else { if ( var_0 [ var_9 ] <= var_1 && var_1 <= var_0 [ var_7 ] ) var_6 = var_9 ; else var_7 = var_9 ; } } if ( var_0 [ var_6 ] == var_1 ) return var_6 ; if ( var_0 [ var_7 ] == var_1 ) return var_7 ; return - 1 ; }
249
<awangdev>Backpack II_6.java
public int backPackII(int m, int[] A, int V[]) { if (A == null || V == null || A.length != V.length) { return 0; } int n = A.length; int[][] dp = new int[2][m + 1]; dp[0][0] = 0; for (int j = 0; j <= m; j++) { dp[0][j] = 0; } int curr = 0, prev; for (int i = 1; i <= n; i++) { prev = curr; curr = 1 - prev; for (int j = 1; j <= m; j++) { dp[curr][j] = dp[prev][j]; if (j - A[i - 1] >= 0) { dp[curr][j] = Math.max(dp[curr][j], dp[prev][j - A[i - 1]] + V[i - 1]); } } } return dp[curr][m]; }
public int sample_funcname ( int var_0 , int [ ] var_1 , int var_2 [ ] ) { if ( var_1 == null || var_2 == null || var_1 . length != var_2 . length ) { return 0 ; } int var_6 = var_1 . length ; int [ ] [ ] var_9 = new int [ 2 ] [ var_0 + 1 ] ; var_9 [ 0 ] [ 0 ] = 0 ; for ( int var_10 = 0 ; var_10 <= var_0 ; var_10 ++ ) { var_9 [ 0 ] [ var_10 ] = 0 ; } int var_11 = 0 , var_12 ; for ( int var_13 = 1 ; var_13 <= var_6 ; var_13 ++ ) { var_12 = var_11 ; var_11 = 1 - var_12 ; for ( int var_10 = 1 ; var_10 <= var_0 ; var_10 ++ ) { var_9 [ var_11 ] [ var_10 ] = var_9 [ var_12 ] [ var_10 ] ; if ( var_10 - var_1 [ var_13 - 1 ] >= 0 ) { var_9 [ var_11 ] [ var_10 ] = Math . max ( var_9 [ var_11 ] [ var_10 ] , var_9 [ var_12 ] [ var_10 - var_1 [ var_13 - 1 ] ] + var_2 [ var_13 - 1 ] ) ; } } } return var_9 [ var_11 ] [ var_0 ] ; }
250
<awangdev>215. Kth Largest Element in an Array_2.java
private void swap(int[] nums, int x, int y) { int temp = nums[x]; nums[x] = nums[y]; nums[y] = temp; }
private void var_0 ( int [ ] var_1 , int var_2 , int var_3 ) { int var_4 = var_1 [ var_2 ] ; var_1 [ var_2 ] = var_1 [ var_3 ] ; var_1 [ var_3 ] = var_4 ; }
251
<awangdev>Compare Version Numbers_2.java
private int compareString(String str1, String str2) { if (str1.equals(str2)) { return 0; } while (str1 != null && str1.length() > 1 && str1.charAt(0) == '0') { str1 = str1.substring(1); } while (str2 != null && str2.length() > 1 && str2.charAt(0) == '0') { str2 = str2.substring(1); } if (str1.length() != str2.length()) { return str1.length() < str2.length() ? -1 : 1; } for (int i = 0; i < str1.length(); i++) { int digit1 = str1.charAt(i) - '0'; int digit2 = str2.charAt(i) - '0'; if (digit1 < digit2) { return -1; } else if (digit1 > digit2) { return 1; } } return 0; }
private int sample_funcname ( String var_1 , String var_2 ) { if ( var_1 . equals ( var_2 ) ) { return 0 ; } while ( var_1 != null && var_1 . length ( ) > 1 && var_1 . charAt ( 0 ) == '0' ) { var_1 = var_1 . substring ( 1 ) ; } while ( var_2 != null && var_2 . length ( ) > 1 && var_2 . charAt ( 0 ) == '0' ) { var_2 = var_2 . substring ( 1 ) ; } if ( var_1 . length ( ) != var_2 . length ( ) ) { return var_1 . length ( ) < var_2 . length ( ) ? - 1 : 1 ; } for ( int var_11 = 0 ; var_11 < var_1 . length ( ) ; var_11 ++ ) { int var_12 = var_1 . charAt ( var_11 ) - '0' ; int var_13 = var_2 . charAt ( var_11 ) - '0' ; if ( var_12 < var_13 ) { return - 1 ; } else if ( var_12 > var_13 ) { return 1 ; } } return 0 ; }
252
<awangdev>Backpack V_2.java
public int backPackV(int[] nums, int target) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; int[][] dp = new int[2][target + 1]; dp[0][0] = 1; for (int j = 1; j <= target; j++) { dp[0][j] = 0; } int curr = 0, prev = 1; for (int i = 1; i <= n; i++) { prev = curr; curr = 1 - curr; for (int j = 0; j <= target; j++) { dp[curr][j] = dp[prev][j]; if (j - nums[i - 1] >= 0) { dp[curr][j] += dp[prev][j - nums[i - 1]]; } } } return dp[curr][target]; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_5 = var_0 . length ; int [ ] [ ] var_8 = new int [ 2 ] [ var_1 + 1 ] ; var_8 [ 0 ] [ 0 ] = 1 ; for ( int var_9 = 1 ; var_9 <= var_1 ; var_9 ++ ) { var_8 [ 0 ] [ var_9 ] = 0 ; } int var_10 = 0 , var_11 = 1 ; for ( int var_12 = 1 ; var_12 <= var_5 ; var_12 ++ ) { var_11 = var_10 ; var_10 = 1 - var_10 ; for ( int var_9 = 0 ; var_9 <= var_1 ; var_9 ++ ) { var_8 [ var_10 ] [ var_9 ] = var_8 [ var_11 ] [ var_9 ] ; if ( var_9 - var_0 [ var_12 - 1 ] >= 0 ) { var_8 [ var_10 ] [ var_9 ] += var_8 [ var_11 ] [ var_9 - var_0 [ var_12 - 1 ] ] ; } } } return var_8 [ var_10 ] [ var_1 ] ; }
253
<awangdev>1106. Parsing A Boolean Expression_3.java
public boolean parseBoolExpr(String exp) { Stack<Character> stack = new Stack<>(); for (char c : exp.toCharArray()) { if (c == ')') { Set<Character> expItems = new HashSet<>(); while (stack.peek() != '(') expItems.add(stack.pop()); stack.pop(); char op = stack.pop(); if (op == '&') stack.push(expItems.contains('f') ? 'f' : 't'); else if (op == '|') stack.push(expItems.contains('t') ? 't' : 'f'); else if (op == '!') stack.push(expItems.contains('t') ? 'f' : 't'); } else if (c != ',') { stack.push(c); } } return stack.pop() == 't'; }
public boolean var_0 ( String var_2 ) { Stack < Character > var_5 = new Stack < > ( ) ; for ( char var_7 : var_2 . toCharArray ( ) ) { if ( var_7 == ')' ) { Set < Character > var_11 = new HashSet < > ( ) ; while ( var_5 . peek ( ) != '(' ) var_11 . add ( var_5 . pop ( ) ) ; var_5 . pop ( ) ; char var_16 = var_5 . pop ( ) ; if ( var_16 == '&' ) var_5 . push ( var_11 . contains ( 'f' ) ? 'f' : 't' ) ; else if ( var_16 == '|' ) var_5 . push ( var_11 . contains ( 't' ) ? 't' : 'f' ) ; else if ( var_16 == '!' ) var_5 . push ( var_11 . contains ( 't' ) ? 'f' : 't' ) ; } else if ( var_7 != ',' ) { var_5 . push ( var_7 ) ; } } return var_5 . pop ( ) == 't' ; }
254
<awangdev>Remove Duplicate Letters_2.java
String removeDuplicateLetters(String s) { if (s == null || s.length() <= 1) { return s; } char[] arr = s.toCharArray(); int[] count = new int[256]; boolean[] visited = new boolean[256]; for (char c : arr) { count[c]++; } Stack<Character> stack = new Stack<>(); stack.push('0'); for (char c : arr) { count[c]--; if (visited[c]) { continue; } while (c < stack.peek() && count[stack.peek()] > 0) { visited[stack.pop()] = false; } stack.push(c); visited[c] = true; } StringBuffer sb = new StringBuffer(); while (!stack.isEmpty()) { sb.insert(0, stack.pop()); } return sb.substring(1).toString(); }
String var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) <= 1 ) { return var_2 ; } char [ ] var_7 = var_2 . toCharArray ( ) ; int [ ] var_9 = new int [ 256 ] ; boolean [ ] var_11 = new boolean [ 256 ] ; for ( char var_12 : var_7 ) { var_9 [ var_12 ] ++ ; } Stack < Character > var_15 = new Stack < > ( ) ; var_15 . push ( '0' ) ; for ( char var_12 : var_7 ) { var_9 [ var_12 ] -- ; if ( var_11 [ var_12 ] ) { continue ; } while ( var_12 < var_15 . peek ( ) && var_9 [ var_15 . peek ( ) ] > 0 ) { var_11 [ var_15 . pop ( ) ] = false ; } var_15 . push ( var_12 ) ; var_11 [ var_12 ] = true ; } StringBuffer var_21 = new StringBuffer ( ) ; while ( ! var_15 . isEmpty ( ) ) { var_21 . insert ( 0 , var_15 . pop ( ) ) ; } return var_21 . substring ( 1 ) . toString ( ) ; }
255
<awangdev>13. Roman to Integer_3.java
private Map<String, Integer> buildSpecialMap() { Map<String, Integer> map = new HashMap<>(); map.put("IV", 4); map.put("IX", 9); map.put("XL", 40); map.put("XC", 90); map.put("CD", 400); map.put("CM", 900); return map; }
private Map < String , Integer > var_2 ( ) { Map < String , Integer > var_5 = new HashMap < > ( ) ; var_5 . put ( "IV" , 4 ) ; var_5 . put ( "IX" , 9 ) ; var_5 . put ( "XL" , 40 ) ; var_5 . put ( "XC" , 90 ) ; var_5 . put ( "CD" , 400 ) ; var_5 . put ( "CM" , 900 ) ; return var_5 ; }
256
<awangdev>1033. Moving Stones Until Consecutive_1.java
public int[] numMovesStones(int a, int b, int c) { int[] arr = new int[]{a, b, c}; Arrays.sort(arr); int max = arr[2] - arr[0] - 2; if (arr[2] - arr[0] == 2) return new int[]{0, max}; if (arr[1] - arr[0] <= 2 || arr[2] - arr[1] <= 2) return new int[]{1, max}; return new int[]{2, max}; }
public int [ ] sample_funcname ( int var_0 , int var_1 , int var_2 ) { int [ ] var_3 = new int [ ] { var_0 , var_1 , var_2 }; Arrays . sort ( var_3 ) ; int var_8 = var_3 [ 2 ] - var_3 [ 0 ] - 2 ; if ( var_3 [ 2 ] - var_3 [ 0 ] == 2 ) return new int [ ] { 0 , var_8 }; if ( var_3 [ 1 ] - var_3 [ 0 ] <= 2 || var_3 [ 2 ] - var_3 [ 1 ] <= 2 ) return new int [ ] { 1 , var_8 }; return new int [ ] { 2 , var_8 }; }
257
<awangdev>Convert Expression to Polish Notation_1.java
public int getWeight(int base, String s) { if (s.equals("+") || s.equals("-")) { return base + 1; } if (s.equals("*") || s.equals("/")) { return base + 2; } return Integer.MAX_VALUE; }
public int sample_funcname ( int var_0 , String var_2 ) { if ( var_2 . equals ( "+" ) || var_2 . equals ( "-" ) ) { return var_0 + 1 ; } if ( var_2 . equals ( "*" ) || var_2 . equals ( "/" ) ) { return var_0 + 2 ; } return Integer . MAX_VALUE ; }
258
<awangdev>Minimum Size Subarray Sum_1.java
public int minSubArrayLen(int s, int[] nums) { if (nums == null || nums.length == 0) { return 0; } int start, end, sum; start = end = sum = 0; int min = Integer.MAX_VALUE; while (end < nums.length) { while (sum < s && end < nums.length) { sum += nums[end]; end++; } while (sum >= s && start >= 0) { min = Math.min(min, end - start); sum -= nums[start]; start++; } } return min == Integer.MAX_VALUE ? 0 : min; }
public int sample_funcname ( int var_0 , int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return 0 ; } int var_5 , var_6 , var_7 ; var_5 = var_6 = var_7 = 0 ; int min = Integer . MAX_VALUE ; while ( var_6 < var_1 . length ) { while ( var_7 < var_0 && var_6 < var_1 . length ) { var_7 += var_1 [ var_6 ] ; var_6 ++ ; } while ( var_7 >= var_0 && var_5 >= 0 ) { min = Math . min ( min , var_6 - var_5 ) ; var_7 -= var_1 [ var_5 ] ; var_5 ++ ; } } return min == Integer . MAX_VALUE ? 0 : min ; }
259
<awangdev>717. 1-bit and 2-bit Characters_1.java
public boolean isOneBitCharacter(int[] bits) { if (bits == null || bits.length == 0) { return false; } int index = 0; while (index < bits.length - 1) { index += bits[index] % 2 == 1 ? 2 : 1; } return index == bits.length - 1; }
public boolean var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return false ; } int var_5 = 0 ; while ( var_5 < var_1 . length - 1 ) { var_5 += var_1 [ var_5 ] % 2 == 1 ? 2 : 1 ; } return var_5 == var_1 . length - 1 ; }
260
<awangdev>Interleaving Positive and Negative Numbers_1.java
public void rerange(int[] A) { if (A == null || A.length <= 1) { return; } Arrays.sort(A); int start = 0; int end = A.length - 1; if (A.length % 2 != 0) { if (A[(start + end) / 2] >= 0) { end--; } else { start++; } } while (start < end) { int temp = A[start]; A[start] = A[end]; A[end] = temp; start += 2; end -= 2; } }
public void var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length <= 1 ) { return ; } Arrays . sort ( var_1 ) ; int var_8 = 0 ; int var_9 = var_1 . length - 1 ; if ( var_1 . length % 2 != 0 ) { if ( var_1 [ ( var_8 + var_9 ) / 2 ] >= 0 ) { var_9 -- ; } else { var_8 ++ ; } } while ( var_8 < var_9 ) { int var_11 = var_1 [ var_8 ] ; var_1 [ var_8 ] = var_1 [ var_9 ] ; var_1 [ var_9 ] = var_11 ; var_8 += 2 ; var_9 -= 2 ; } }
261
<awangdev>Maximum Subarray II_5.java
public int maxTwoSubArrays(ArrayList<Integer> nums) { if (nums == null || nums.size() == 0) { return 0; } int[] frontSum = new int[nums.size()]; int[] endSum = new int[nums.size()]; int maxSum = 0; frontSum[0] = nums.get(0); for (int i = 1; i < frontSum.length; i++) { if (frontSum[i - 1] < 0) { frontSum[i] = nums.get(i); } else { frontSum[i] = frontSum[i - 1] + nums.get(i); } } maxSum = frontSum[0]; for (int i = 1; i < frontSum.length; i++) { if (frontSum[i] < maxSum) { frontSum[i] = maxSum; } else { maxSum = frontSum[i]; } } endSum[endSum.length - 1] = nums.get(nums.size() - 1); for (int i = endSum.length - 2; i >= 0; i--) { if (endSum[i + 1] < 0) { endSum[i] = nums.get(i); } else { endSum[i] = endSum[i + 1] + nums.get(i); } } maxSum = endSum[endSum.length - 1]; for (int i = endSum.length - 2; i >= 0; i--) { if (endSum[i] < maxSum) { endSum[i] = maxSum; } else { maxSum = endSum[i]; } } maxSum = Integer.MIN_VALUE; for (int i = 0; i < nums.size() - 1; i++) { maxSum = Math.max(maxSum, frontSum[i] + endSum[i + 1]); } return maxSum; }
public int sample_funcname ( ArrayList < Integer > var_2 ) { if ( var_2 == null || var_2 . size ( ) == 0 ) { return 0 ; } int [ ] var_6 = new int [ var_2 . size ( ) ] ; int [ ] var_7 = new int [ var_2 . size ( ) ] ; int var_8 = 0 ; var_6 [ 0 ] = var_2 . get ( 0 ) ; for ( int var_11 = 1 ; var_11 < var_6 . length ; var_11 ++ ) { if ( var_6 [ var_11 - 1 ] < 0 ) { var_6 [ var_11 ] = var_2 . get ( var_11 ) ; } else { var_6 [ var_11 ] = var_6 [ var_11 - 1 ] + var_2 . get ( var_11 ) ; } } var_8 = var_6 [ 0 ] ; for ( int var_11 = 1 ; var_11 < var_6 . length ; var_11 ++ ) { if ( var_6 [ var_11 ] < var_8 ) { var_6 [ var_11 ] = var_8 ; } else { var_8 = var_6 [ var_11 ] ; } } var_7 [ var_7 . length - 1 ] = var_2 . get ( var_2 . size ( ) - 1 ) ; for ( int var_11 = var_7 . length - 2 ; var_11 >= 0 ; var_11 -- ) { if ( var_7 [ var_11 + 1 ] < 0 ) { var_7 [ var_11 ] = var_2 . get ( var_11 ) ; } else { var_7 [ var_11 ] = var_7 [ var_11 + 1 ] + var_2 . get ( var_11 ) ; } } var_8 = var_7 [ var_7 . length - 1 ] ; for ( int var_11 = var_7 . length - 2 ; var_11 >= 0 ; var_11 -- ) { if ( var_7 [ var_11 ] < var_8 ) { var_7 [ var_11 ] = var_8 ; } else { var_8 = var_7 [ var_11 ] ; } } var_8 = Integer . MIN_VALUE ; for ( int var_11 = 0 ; var_11 < var_2 . size ( ) - 1 ; var_11 ++ ) { var_8 = Math . max ( var_8 , var_6 [ var_11 ] + var_7 [ var_11 + 1 ] ) ; } return var_8 ; }
262
<awangdev>1203. Sort Items by Groups Respecting Dependencies_3.java
private Map<Integer, List<Integer>> buildItemGraph(List<Integer> items, List<List<Integer>> beforeItems) { Map<Integer, List<Integer>> graph = new HashMap<>(); for (int i : items) { for (int item : beforeItems.get(i)) { graph.putIfAbsent(item, new ArrayList<>()); graph.get(item).add(i); } } return graph; }
private Map < Integer , List < Integer >> var_2 ( List < Integer > var_3 , List < List < Integer >> var_4 ) { Map < Integer , List < Integer >> var_7 = new HashMap < > ( ) ; for ( int var_8 : var_3 ) { for ( int var_10 : var_4 . get ( var_8 ) ) { var_7 . putIfAbsent ( var_10 , new ArrayList < > ( ) ) ; var_7 . get ( var_10 ) . add ( var_8 ) ; } } return var_7 ; }
263
<awangdev>256. Paint House_2.java
public int minCost(int[][] costs) { if (costs == null || costs.length == 0) return 0; int n = costs.length, m = costs[0].length; int[][] dp = new int[n + 1][m]; for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j++) { dp[i][j] = Integer.MAX_VALUE; for (int k = 0; k < m; k++) { if (j == k) continue; dp[i][j] = Math.min(dp[i][j], dp[i - 1][k] + costs[i - 1][j]); } } } int min = Integer.MAX_VALUE; for (int j = 0; j < m; j++) min = Math.min(min, dp[n][j]); return min; }
public int sample_funcname ( int [ ] [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length , var_5 = var_0 [ 0 ] . length ; int [ ] [ ] var_7 = new int [ var_4 + 1 ] [ var_5 ] ; for ( int var_8 = 1 ; var_8 <= var_4 ; var_8 ++ ) { for ( int var_9 = 0 ; var_9 < var_5 ; var_9 ++ ) { var_7 [ var_8 ] [ var_9 ] = Integer . MAX_VALUE ; for ( int var_12 = 0 ; var_12 < var_5 ; var_12 ++ ) { if ( var_9 == var_12 ) continue ; var_7 [ var_8 ] [ var_9 ] = Math . min ( var_7 [ var_8 ] [ var_9 ] , var_7 [ var_8 - 1 ] [ var_12 ] + var_0 [ var_8 - 1 ] [ var_9 ] ) ; } } } int min = Integer . MAX_VALUE ; for ( int var_9 = 0 ; var_9 < var_5 ; var_9 ++ ) min = Math . min ( min , var_7 [ var_4 ] [ var_9 ] ) ; return min ; }
264
<awangdev>4Sum_2.java
public ArrayList<ArrayList<Integer>> fourSum(int[] numbers, int target) { ArrayList<ArrayList<Integer>> rst = new ArrayList<ArrayList<Integer>>(); if(numbers == null || numbers.length < 4) { return rst; } Arrays.sort(numbers); for (int i = 0; i < numbers.length - 3; i++) { if (i != 0 && numbers[i] == numbers[i - 1]) { continue; } for (int j = i + 1; j < numbers.length - 2; j++) { if (j != i + 1 && numbers[j] == numbers[j - 1]) { continue; } int third = j + 1; int fourth = numbers.length - 1; while (third < fourth) { int sum = numbers[i] + numbers[j] + numbers[third] + numbers[fourth]; if (sum < target) { third++; } else if (sum > target) { fourth--; } else { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(numbers[i]); list.add(numbers[j]); list.add(numbers[third]); list.add(numbers[fourth]); rst.add(list); third++; fourth--; while (third < fourth && numbers[third] == numbers[third - 1]) { third++; } while (third < fourth && numbers[fourth] == numbers[fourth + 1]){ fourth--; } } } } } return rst; }
public ArrayList < ArrayList < Integer >> var_2 ( int [ ] var_3 , int var_4 ) { ArrayList < ArrayList < Integer >> var_5 = new ArrayList < ArrayList < Integer >> ( ) ; if ( var_3 == null || var_3 . length < 4 ) { return var_5 ; } Arrays . sort ( var_3 ) ; for ( int var_12 = 0 ; var_12 < var_3 . length - 3 ; var_12 ++ ) { if ( var_12 != 0 && var_3 [ var_12 ] == var_3 [ var_12 - 1 ] ) { continue ; } for ( int var_15 = var_12 + 1 ; var_15 < var_3 . length - 2 ; var_15 ++ ) { if ( var_15 != var_12 + 1 && var_3 [ var_15 ] == var_3 [ var_15 - 1 ] ) { continue ; } int var_17 = var_15 + 1 ; int var_18 = var_3 . length - 1 ; while ( var_17 < var_18 ) { int var_19 = var_3 [ var_12 ] + var_3 [ var_15 ] + var_3 [ var_17 ] + var_3 [ var_18 ] ; if ( var_19 < var_4 ) { var_17 ++ ; } else if ( var_19 > var_4 ) { var_18 -- ; } else { ArrayList < Integer > var_20 = new ArrayList < Integer > ( ) ; var_20 . add ( var_3 [ var_12 ] ) ; var_20 . add ( var_3 [ var_15 ] ) ; var_20 . add ( var_3 [ var_17 ] ) ; var_20 . add ( var_3 [ var_18 ] ) ; var_5 . add ( var_20 ) ; var_17 ++ ; var_18 -- ; while ( var_17 < var_18 && var_3 [ var_17 ] == var_3 [ var_17 - 1 ] ) { var_17 ++ ; } while ( var_17 < var_18 && var_3 [ var_18 ] == var_3 [ var_18 + 1 ] ) { var_18 -- ; } } } } } return var_5 ; }
265
<awangdev>68. Text Justification_2.java
private String generateSpace(int n) { if (n <= 0) return ""; StringBuffer sb = new StringBuffer(); for (int i = 0; i < n; i++) sb.append(" "); return sb.toString(); }
private String var_0 ( int var_1 ) { if ( var_1 <= 0 ) return "" ; StringBuffer var_5 = new StringBuffer ( ) ; for ( int var_6 = 0 ; var_6 < var_1 ; var_6 ++ ) var_5 . append ( " " ) ; return var_5 . toString ( ) ; }
266
<awangdev>Ones and Zeroes_2.java
public int findMaxForm(String[] strs, int m, int n) { if (strs == null || strs.length == 0 || (m == 0 && n == 0)) { return 0; } int len = strs.length; int[][][] dp = new int[m + 1][n + 1][2]; int curr = 1; int prev = 0; int[] ones = new int[len]; int[] zeros = new int[len]; for (int k = 0; k < len; k++) { char[] ss = strs[k].toCharArray(); for (char c : ss) { ones[k] += c == '1' ? 1 : 0; zeros[k] += c == '0' ? 1 : 0; } } for (int k = 0; k <= len; k++) { prev = curr; curr = 1 - prev; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (k == 0 || (i == 0 && j == 0)) { dp[i][j][curr] = 0; continue; } dp[i][j][curr] = dp[i][j][prev]; int countZero = zeros[k - 1]; int countOne = ones[k - 1]; if (i >= countZero && j >= countOne) { dp[i][j][curr] = Math.max(dp[i][j][curr], dp[i - countZero][j - countOne][prev] + 1); } } } } return dp[m][n][curr]; }
public int sample_funcname ( String [ ] var_1 , int var_2 , int var_3 ) { if ( var_1 == null || var_1 . length == 0 || ( var_2 == 0 && var_3 == 0 ) ) { return 0 ; } int var_7 = var_1 . length ; int [ ] [ ] [ ] var_10 = new int [ var_2 + 1 ] [ var_3 + 1 ] [ 2 ] ; int var_11 = 1 ; int var_12 = 0 ; int [ ] var_13 = new int [ var_7 ] ; int [ ] var_14 = new int [ var_7 ] ; for ( int var_15 = 0 ; var_15 < var_7 ; var_15 ++ ) { char [ ] var_17 = var_1 [ var_15 ] . toCharArray ( ) ; for ( char var_18 : var_17 ) { var_13 [ var_15 ] += var_18 == '1' ? 1 : 0 ; var_14 [ var_15 ] += var_18 == '0' ? 1 : 0 ; } } for ( int var_15 = 0 ; var_15 <= var_7 ; var_15 ++ ) { var_12 = var_11 ; var_11 = 1 - var_12 ; for ( int var_21 = 0 ; var_21 <= var_2 ; var_21 ++ ) { for ( int var_22 = 0 ; var_22 <= var_3 ; var_22 ++ ) { if ( var_15 == 0 || ( var_21 == 0 && var_22 == 0 ) ) { var_10 [ var_21 ] [ var_22 ] [ var_11 ] = 0 ; continue ; } var_10 [ var_21 ] [ var_22 ] [ var_11 ] = var_10 [ var_21 ] [ var_22 ] [ var_12 ] ; int var_23 = var_14 [ var_15 - 1 ] ; int var_24 = var_13 [ var_15 - 1 ] ; if ( var_21 >= var_23 && var_22 >= var_24 ) { var_10 [ var_21 ] [ var_22 ] [ var_11 ] = Math . max ( var_10 [ var_21 ] [ var_22 ] [ var_11 ] , var_10 [ var_21 - var_23 ] [ var_22 - var_24 ] [ var_12 ] + 1 ) ; } } } } return var_10 [ var_2 ] [ var_3 ] [ var_11 ] ; }
267
<awangdev>Best Time to Buy and Sell Stock IV_4.java
public int maxProfit(int k, int[] prices) { if (prices == null || prices.length < 2 || k <= 0) { return 0; } if (k >= prices.length) { int profit = 0; for (int i = 1; i < prices.length; i++) { if (prices[i] > prices[i - 1]) { profit += prices[i] - prices[i - 1]; } } return profit; } int[][] local = new int[prices.length][k + 1]; int[][] global = new int[prices.length][k + 1]; for (int i = 1; i < prices.length; i++) { int diff = prices[i] - prices[i - 1]; for (int j = 1; j <= k; j++) { local[i][j] = Math.max(global[i-1][j-1] + diff, local[i - 1][j] + diff); global[i][j] = Math.max(global[i-1][j], local[i][j]); } } return global[prices.length - 1][k]; }
public int sample_funcname ( int var_0 , int [ ] var_1 ) { if ( var_1 == null || var_1 . length < 2 || var_0 <= 0 ) { return 0 ; } if ( var_0 >= var_1 . length ) { int var_6 = 0 ; for ( int var_8 = 1 ; var_8 < var_1 . length ; var_8 ++ ) { if ( var_1 [ var_8 ] > var_1 [ var_8 - 1 ] ) { var_6 += var_1 [ var_8 ] - var_1 [ var_8 - 1 ] ; } } return var_6 ; } int [ ] [ ] var_9 = new int [ var_1 . length ] [ var_0 + 1 ] ; int [ ] [ ] var_10 = new int [ var_1 . length ] [ var_0 + 1 ] ; for ( int var_8 = 1 ; var_8 < var_1 . length ; var_8 ++ ) { int var_11 = var_1 [ var_8 ] - var_1 [ var_8 - 1 ] ; for ( int var_12 = 1 ; var_12 <= var_0 ; var_12 ++ ) { var_9 [ var_8 ] [ var_12 ] = Math . max ( var_10 [ var_8 - 1 ] [ var_12 - 1 ] + var_11 , var_9 [ var_8 - 1 ] [ var_12 ] + var_11 ) ; var_10 [ var_8 ] [ var_12 ] = Math . max ( var_10 [ var_8 - 1 ] [ var_12 ] , var_9 [ var_8 ] [ var_12 ] ) ; } } return var_10 [ var_1 . length - 1 ] [ var_0 ] ; }
268
<awangdev>387. First Unique Character in a String_1.java
public int firstUniqChar(String s) { int[] freq = new int[256]; for (char c : s.toCharArray()) freq[c - 'a']++; for (int i = 0; i < s.length(); i++) { if (freq[s.charAt(i) - 'a'] == 1) return i; } return -1; }
public int sample_funcname ( String var_1 ) { int [ ] var_3 = new int [ 256 ] ; for ( char var_5 : var_1 . toCharArray ( ) ) var_3 [ var_5 - 'a' ] ++ ; for ( int var_8 = 0 ; var_8 < var_1 . length ( ) ; var_8 ++ ) { if ( var_3 [ var_1 . charAt ( var_8 ) - 'a' ] == 1 ) return var_8 ; } return - 1 ; }
269
<awangdev>78. Subsets_3.java
public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> result = new ArrayList<>(); if (nums == null || nums.length == 0) { return result; } int n = nums.length; long maxRange = (long) Math.pow(2, n) - 1; for (int i = 0; i <= maxRange; i++) { List<Integer> list = new ArrayList<>(); int index = 0; int num = i; while (num != 0) { if ((num & 1) == 1) { list.add(nums[index]); } num = num >> 1; index++; } result.add(list); } return result; }
public List < List < Integer >> var_2 ( int [ ] var_3 ) { List < List < Integer >> var_5 = new ArrayList < > ( ) ; if ( var_3 == null || var_3 . length == 0 ) { return var_5 ; } int var_9 = var_3 . length ; long var_14 = ( long ) Math . pow ( 2 , var_9 ) - 1 ; for ( int var_15 = 0 ; var_15 <= var_14 ; var_15 ++ ) { List < Integer > var_16 = new ArrayList < > ( ) ; int var_17 = 0 ; int var_18 = var_15 ; while ( var_18 != 0 ) { if ( ( var_18 & 1 ) == 1 ) { var_16 . add ( var_3 [ var_17 ] ) ; } var_18 = var_18 >> 1 ; var_17 ++ ; } var_5 . add ( var_16 ) ; } return var_5 ; }
270
<awangdev>720. Longest Word in Dictionary_2.java
private ArrayList<String> matchWords(ArrayList<String> wordList) { int maxWordLength = Integer.MIN_VALUE; ArrayList<String> result = new ArrayList<>(); for (int i = wordList.size() - 1; i >= 0; i--) { String word = wordList.get(i); while(word.length() != 0) { if (wordList.contains(word)) { if (word.length() == 1) { if (wordList.get(i).length() < maxWordLength) { return result; } else { result.add(wordList.get(i)); maxWordLength = wordList.get(i).length(); } } word = word.substring(0, word.length() - 1); } else { break; } } } return result; }
private ArrayList < String > var_1 ( ArrayList < String > var_3 ) { int var_6 = Integer . MIN_VALUE ; ArrayList < String > var_7 = new ArrayList < > ( ) ; for ( int var_10 = var_3 . size ( ) - 1 ; var_10 >= 0 ; var_10 -- ) { String var_13 = var_3 . get ( var_10 ) ; while ( var_13 . length ( ) != 0 ) { if ( var_3 . contains ( var_13 ) ) { if ( var_13 . length ( ) == 1 ) { if ( var_3 . get ( var_10 ) . length ( ) < var_6 ) { return var_7 ; } else { var_7 . add ( var_3 . get ( var_10 ) ) ; var_6 = var_3 . get ( var_10 ) . length ( ) ; } } var_13 = var_13 . substring ( 0 , var_13 . length ( ) - 1 ) ; } else { break ; } } } return var_7 ; }
271
<awangdev>Copy Books_4.java
private int validate(int[] pages, int totalTimePerPerson, int k) { int temp = 0; for (int i = 0; i < pages.length; i++) { temp += pages[i]; if (temp == totalTimePerPerson) { temp = 0; k--; } else if (temp < totalTimePerPerson) { if (i + 1 >= pages.length || temp + pages[i + 1] > totalTimePerPerson) { temp = 0; k--; } } else { return -1; } } return k; }
private int sample_funcname ( int [ ] var_0 , int var_1 , int var_2 ) { int var_4 = 0 ; for ( int var_5 = 0 ; var_5 < var_0 . length ; var_5 ++ ) { var_4 += var_0 [ var_5 ] ; if ( var_4 == var_1 ) { var_4 = 0 ; var_2 -- ; } else if ( var_4 < var_1 ) { if ( var_5 + 1 >= var_0 . length || var_4 + var_0 [ var_5 + 1 ] > var_1 ) { var_4 = 0 ; var_2 -- ; } } else { return - 1 ; } } return var_2 ; }
272
<awangdev>House Robber II_3.java
public int rob(int[] nums) { if (nums == null || nums.length == 0) { return 0; } else if (nums.length == 1) { return nums[0]; } int n = nums.length; int[][] dp = new int[n][2]; dp[0][0] = 0; dp[1][0] = nums[1]; dp[0][1] = nums[0]; dp[1][1] = dp[0][1]; for (int i = 2; i < n; i++) { if (i == n - 1) { dp[i][0] = Math.max(dp[i - 1][0], dp[i -2][0] + nums[i]); dp[i][1] = dp[i - 1][1]; } else { dp[i][0] = Math.max(dp[i - 1][0], dp[i -2][0] + nums[i]); dp[i][1] = Math.max(dp[i - 1][1], dp[i -2][1] + nums[i]); } } return Math.max(dp[n - 1][0], dp[n - 1][1]); }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } else if ( var_0 . length == 1 ) { return var_0 [ 0 ] ; } int var_5 = var_0 . length ; int [ ] [ ] var_7 = new int [ var_5 ] [ 2 ] ; var_7 [ 0 ] [ 0 ] = 0 ; var_7 [ 1 ] [ 0 ] = var_0 [ 1 ] ; var_7 [ 0 ] [ 1 ] = var_0 [ 0 ] ; var_7 [ 1 ] [ 1 ] = var_7 [ 0 ] [ 1 ] ; for ( int var_8 = 2 ; var_8 < var_5 ; var_8 ++ ) { if ( var_8 == var_5 - 1 ) { var_7 [ var_8 ] [ 0 ] = Math . max ( var_7 [ var_8 - 1 ] [ 0 ] , var_7 [ var_8 - 2 ] [ 0 ] + var_0 [ var_8 ] ) ; var_7 [ var_8 ] [ 1 ] = var_7 [ var_8 - 1 ] [ 1 ] ; } else { var_7 [ var_8 ] [ 0 ] = Math . max ( var_7 [ var_8 - 1 ] [ 0 ] , var_7 [ var_8 - 2 ] [ 0 ] + var_0 [ var_8 ] ) ; var_7 [ var_8 ] [ 1 ] = Math . max ( var_7 [ var_8 - 1 ] [ 1 ] , var_7 [ var_8 - 2 ] [ 1 ] + var_0 [ var_8 ] ) ; } } return Math . max ( var_7 [ var_5 - 1 ] [ 0 ] , var_7 [ var_5 - 1 ] [ 1 ] ) ; }
273
<awangdev>299. Bulls and Cows_2.java
public String getHint(String secret, String guess) { if (secret == null || guess == null || secret.length() == 0 || guess.length() == 0) { return "0A0B"; } char[] secretArr = secret.toCharArray(); char[] guessArr = guess.toCharArray(); Map<Character, Integer> secretMap = new HashMap<>(); Map<Character, Integer> guessMap = new HashMap<>(); int bulls = 0; for (int i = 0; i < secretArr.length; i++) { char a = secretArr[i], b = guessArr[i]; if (a == b) { bulls++; } else { secretMap.putIfAbsent(a, 0); secretMap.put(a, secretMap.get(a) + 1); guessMap.putIfAbsent(b, 0); guessMap.put(b, guessMap.get(b) + 1); } } int cows = 0; for (Map.Entry<Character, Integer> entry : secretMap.entrySet()) { char key = entry.getKey(); if (guessMap.containsKey(key)) { cows += Math.min(entry.getValue(), guessMap.get(key)); } } return String.format("%sA%sB", bulls, cows); }
public String var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_3 == null || var_2 . length ( ) == 0 || var_3 . length ( ) == 0 ) { return "0A0B" ; } char [ ] var_9 = var_2 . toCharArray ( ) ; char [ ] var_10 = var_3 . toCharArray ( ) ; Map < Character , Integer > var_15 = new HashMap < > ( ) ; Map < Character , Integer > var_16 = new HashMap < > ( ) ; int var_17 = 0 ; for ( int var_18 = 0 ; var_18 < var_9 . length ; var_18 ++ ) { char var_19 = var_9 [ var_18 ] , var_20 = var_10 [ var_18 ] ; if ( var_19 == var_20 ) { var_17 ++ ; } else { var_15 . putIfAbsent ( var_19 , 0 ) ; var_15 . put ( var_19 , var_15 . get ( var_19 ) + 1 ) ; var_16 . putIfAbsent ( var_20 , 0 ) ; var_16 . put ( var_20 , var_16 . get ( var_20 ) + 1 ) ; } } int var_25 = 0 ; for ( Map . Entry < Character , Integer > var_27 : var_15 . entrySet ( ) ) { char var_29 = var_27 . getKey ( ) ; if ( var_16 . containsKey ( var_29 ) ) { var_25 += Math . min ( var_27 . getValue ( ) , var_16 . get ( var_29 ) ) ; } } return String . format ( "%sA%sB" , var_17 , var_25 ) ; }
274
<awangdev>261. Graph Valid Tree_1.java
private Map<Integer, Set<Integer>> buildGraph(int n, int[][] edges) { Map<Integer, Set<Integer>> graph = new HashMap<>(); for (int i = 0; i < n; i++) graph.putIfAbsent(i, new HashSet<>()); for (int[] edge: edges) { graph.get(edge[0]).add(edge[1]); graph.get(edge[1]).add(edge[0]); } return graph; }
private Map < Integer , Set < Integer >> var_2 ( int var_3 , int [ ] [ ] var_4 ) { Map < Integer , Set < Integer >> var_7 = new HashMap < > ( ) ; for ( int var_9 = 0 ; var_9 < var_3 ; var_9 ++ ) var_7 . putIfAbsent ( var_9 , new HashSet < > ( ) ) ; for ( int [ ] var_12 : var_4 ) { var_7 . get ( var_12 [ 0 ] ) . add ( var_12 [ 1 ] ) ; var_7 . get ( var_12 [ 1 ] ) . add ( var_12 [ 0 ] ) ; } return var_7 ; }
275
<awangdev>118. Pascal's Triangle_1.java
public List<List<Integer>> generate(int numRows) { List<List<Integer>> result = new ArrayList<>(); if (numRows == 0) return result; if (numRows >= 1) result.add(Arrays.asList(1)); if (numRows >= 2) result.add(Arrays.asList(1, 1)); for (int row = 2; row < numRows; row++) { List<Integer> list = new ArrayList<>(Arrays.asList(1, 1)); List<Integer> lastRow = result.get(row - 1); int end = row - 1; for (int i = 1; i <= end; i++) { list.add(i, lastRow.get(i) + lastRow.get(i - 1)); } result.add(list); } return result; }
public List < List < Integer >> var_2 ( int var_3 ) { List < List < Integer >> var_5 = new ArrayList < > ( ) ; if ( var_3 == 0 ) return var_5 ; if ( var_3 >= 1 ) var_5 . add ( Arrays . asList ( 1 ) ) ; if ( var_3 >= 2 ) var_5 . add ( Arrays . asList ( 1 , 1 ) ) ; for ( int var_12 = 2 ; var_12 < var_3 ; var_12 ++ ) { List < Integer > var_13 = new ArrayList < > ( Arrays . asList ( 1 , 1 ) ) ; List < Integer > var_15 = var_5 . get ( var_12 - 1 ) ; int var_16 = var_12 - 1 ; for ( int var_17 = 1 ; var_17 <= var_16 ; var_17 ++ ) { var_13 . add ( var_17 , var_15 . get ( var_17 ) + var_15 . get ( var_17 - 1 ) ) ; } var_5 . add ( var_13 ) ; } return var_5 ; }
276
<awangdev>[lint]. HashHeap_1.java
int parent(int id) { if (id == 0) { return -1; } return (id - 1) / 2; }
int sample_funcname ( int var_0 ) { if ( var_0 == 0 ) { return - 1 ; } return ( var_0 - 1 ) / 2 ; }
277
<awangdev>122. Best Time to Buy and Sell Stock II_6.java
private int dfs(int[] prices, int index, boolean sellStatus) { if (index == prices.length - 1) { return sellStatus ? prices[index] : 0; } int profit = 0; for (int i = index; i < prices.length; i++) { profit = Math.max(profit, dfs(prices, i + 1, sellStatus)); int levelDelta = sellStatus ? prices[i] : - prices[i]; profit = Math.max(profit, dfs(prices, i + 1, !sellStatus) + levelDelta); } return profit; }
private int sample_funcname ( int [ ] prices , int index , boolean sellStatus ) { if ( index == prices . length - 1 ) { return sellStatus ? prices [ index ] : 0 ; } int profit = 0 ; for ( int i = index ; i < prices . length ; i ++ ) { profit = Math . max ( profit , dfs ( prices , i + 1 , sellStatus ) ) ; int levelDelta = sellStatus ? prices [ i ] : - prices [ i ] ; profit = Math . max ( profit , dfs ( prices , i + 1 , ! sellStatus ) + levelDelta ) ; } return profit ; }
278
<awangdev>340. Longest Substring with At Most K Distinct Characters_3.java
public int lengthOfLongestSubstringKDistinct(String s, int k) { if (s == null || s.length() == 0) return 0; int n = s.length(); Map<Character, Integer> lastOccurMap = new LinkedHashMap<>(k + 1); int left = 0, right = 0, max = 0; while (right < n) { char c = s.charAt(right); if (lastOccurMap.containsKey(c)) lastOccurMap.remove(c); lastOccurMap.put(c, right++); if (lastOccurMap.size() > k) { Map.Entry<Character, Integer> leftMost = lastOccurMap.entrySet().iterator().next(); lastOccurMap.remove(leftMost.getKey()); left = leftMost.getValue() + 1; } max = Math.max(max, right - left); } return max; }
public int sample_funcname ( String var_1 , int var_2 ) { if ( var_1 == null || var_1 . length ( ) == 0 ) return 0 ; int var_6 = var_1 . length ( ) ; Map < Character , Integer > var_12 = new LinkedHashMap < > ( var_2 + 1 ) ; int var_13 = 0 , var_14 = 0 , max = 0 ; while ( var_14 < var_6 ) { char var_17 = var_1 . charAt ( var_14 ) ; if ( var_12 . containsKey ( var_17 ) ) var_12 . remove ( var_17 ) ; var_12 . put ( var_17 , var_14 ++ ) ; if ( var_12 . size ( ) > var_2 ) { Map . Entry < Character , Integer > var_26 = var_12 . entrySet ( ) . iterator ( ) . next ( ) ; var_12 . remove ( var_26 . getKey ( ) ) ; var_13 = var_26 . getValue ( ) + 1 ; } max = Math . max ( max , var_14 - var_13 ) ; } return max ; }
279
<awangdev>Flip Game II_1.java
private void setSign(boolean[] sign, int i, boolean value) { sign[i] = value; sign[i + 1] = value; }
private void var_0 ( boolean [ ] var_2 , int var_3 , boolean var_4 ) { var_2 [ var_3 ] = var_4 ; var_2 [ var_3 + 1 ] = var_4 ; }
280
<awangdev>41. First Missing Positive_2.java
public int firstMissingPositive(int[] A) { if (A == null || A.length == 0) { return 1; } Arrays.sort(A); int count = -1; for (int i = 0; i < A.length; i++) { if (A[i] > 0) { if (count < 0) { count = A[i]; if (count != 1) { return 1; } } else if (A[i] == A[i - 1]) { count--; } else if(A[i] != count) { return count; } count++; } } if (count < 0) { return 1; } return count; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 1 ; } Arrays . sort ( var_0 ) ; int var_7 = - 1 ; for ( int var_8 = 0 ; var_8 < var_0 . length ; var_8 ++ ) { if ( var_0 [ var_8 ] > 0 ) { if ( var_7 < 0 ) { var_7 = var_0 [ var_8 ] ; if ( var_7 != 1 ) { return 1 ; } } else if ( var_0 [ var_8 ] == var_0 [ var_8 - 1 ] ) { var_7 -- ; } else if ( var_0 [ var_8 ] != var_7 ) { return var_7 ; } var_7 ++ ; } } if ( var_7 < 0 ) { return 1 ; } return var_7 ; }
281
<awangdev>Nim Game_4.java
public boolean canWinNim(int n) { if (n <= 3) { return true; } boolean[] dp = new boolean[3]; dp[0] = dp[1] = dp[2] = true; for (int i = 3; i < n; i++) { dp[i % 3] = !dp[(i - 1) % 3] || !dp[(i - 2) % 3] || !dp[(i - 3) % 3]; } return dp[(n - 1) % 3]; }
public boolean var_0 ( int var_1 ) { if ( var_1 <= 3 ) { return true ; } boolean [ ] var_4 = new boolean [ 3 ] ; var_4 [ 0 ] = var_4 [ 1 ] = var_4 [ 2 ] = true ; for ( int var_8 = 3 ; var_8 < var_1 ; var_8 ++ ) { var_4 [ var_8 % 3 ] = ! var_4 [ ( var_8 - 1 ) % 3 ] || ! var_4 [ ( var_8 - 2 ) % 3 ] || ! var_4 [ ( var_8 - 3 ) % 3 ] ; } return var_4 [ ( var_1 - 1 ) % 3 ] ; }
282
<awangdev>Triangle Count_1.java
public int triangleNumber(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int count = 0; Arrays.sort(nums); for (int i = 2; i < nums.length; i++) { int start = 0; int end = i - 1; while (start < end) { if (nums[start] + nums[end] > nums[i]) { count += end - start; end--; } else { start++; } } } return count; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = 0 ; Arrays . sort ( var_0 ) ; for ( int var_8 = 2 ; var_8 < var_0 . length ; var_8 ++ ) { int var_9 = 0 ; int var_11 = var_8 - 1 ; while ( var_9 < var_11 ) { if ( var_0 [ var_9 ] + var_0 [ var_11 ] > var_0 [ var_8 ] ) { var_4 += var_11 - var_9 ; var_11 -- ; } else { var_9 ++ ; } } } return var_4 ; }
283
<awangdev>674. Longest Continuous Increasing Subsequence_4.java
public int findLengthOfLCIS(int[] nums) { if (nums == null || nums.length == 0) return 0; int n = nums.length; int[] dp = new int[2]; dp[0] = 1; int max = 1; for (int i = 1; i < n; i++) { dp[i%2] = 1; if (nums[i] > nums[i - 1]) dp[i%2] = Math.max(dp[i%2], dp[(i - 1)%2] + 1); max = Math.max(max, dp[i%2]); } return max; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length ; int [ ] var_6 = new int [ 2 ] ; var_6 [ 0 ] = 1 ; int max = 1 ; for ( int var_9 = 1 ; var_9 < var_4 ; var_9 ++ ) { var_6 [ var_9 % 2 ] = 1 ; if ( var_0 [ var_9 ] > var_0 [ var_9 - 1 ] ) var_6 [ var_9 % 2 ] = Math . max ( var_6 [ var_9 % 2 ] , var_6 [ ( var_9 - 1 ) % 2 ] + 1 ) ; max = Math . max ( max , var_6 [ var_9 % 2 ] ) ; } return max ; }
284
<awangdev>42. Trapping Rain Water_2.java
public int trap(int[] height) { if (height == null || height.length == 0) return 0; int n = height.length, left = 0, right = n - 1; int maxLeft = height[0], maxRight = height[n - 1]; int total = 0; while (left < right) { if (maxLeft < maxRight) { left++; if (maxLeft > height[left]) total += maxLeft - height[left]; else maxLeft = height[left]; } else { right--; if (maxRight > height[right]) total += maxRight - height[right]; else maxRight = height[right]; } } return total; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length , var_5 = 0 , var_7 = var_4 - 1 ; int var_8 = var_0 [ 0 ] , var_9 = var_0 [ var_4 - 1 ] ; int var_10 = 0 ; while ( var_5 < var_7 ) { if ( var_8 < var_9 ) { var_5 ++ ; if ( var_8 > var_0 [ var_5 ] ) var_10 += var_8 - var_0 [ var_5 ] ; else var_8 = var_0 [ var_5 ] ; } else { var_7 -- ; if ( var_9 > var_0 [ var_7 ] ) var_10 += var_9 - var_0 [ var_7 ] ; else var_9 = var_0 [ var_7 ] ; } } return var_10 ; }
285
<awangdev>Number of Longest Increasing Subsequence_1.java
public int findNumberOfLIS(int[] nums) { if (nums == null || nums.length == 0) return 0; int n = nums.length, maxLen = 0, maxFreq = 0; int[] len = new int[n]; int[] count = new int[n]; for (int i = 0; i < n; i++) { len[i] = 1; count[i] = 1; for (int j = 0; j < i; j++) { if (nums[j] < nums[i]) { if (len[i] == len[j] + 1) { count[i] += count[j]; } else if (len[i] < len[j] + 1) { len[i] = len[j] + 1; count[i] = count[j]; } } } if (maxLen == len[i]) { maxFreq += count[i]; } else if (maxLen < len[i]) { maxLen = len[i]; maxFreq = count[i]; } } return maxFreq; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length , var_5 = 0 , var_6 = 0 ; int [ ] var_7 = new int [ var_4 ] ; int [ ] var_8 = new int [ var_4 ] ; for ( int var_9 = 0 ; var_9 < var_4 ; var_9 ++ ) { var_7 [ var_9 ] = 1 ; var_8 [ var_9 ] = 1 ; for ( int var_11 = 0 ; var_11 < var_9 ; var_11 ++ ) { if ( var_0 [ var_11 ] < var_0 [ var_9 ] ) { if ( var_7 [ var_9 ] == var_7 [ var_11 ] + 1 ) { var_8 [ var_9 ] += var_8 [ var_11 ] ; } else if ( var_7 [ var_9 ] < var_7 [ var_11 ] + 1 ) { var_7 [ var_9 ] = var_7 [ var_11 ] + 1 ; var_8 [ var_9 ] = var_8 [ var_11 ] ; } } } if ( var_5 == var_7 [ var_9 ] ) { var_6 += var_8 [ var_9 ] ; } else if ( var_5 < var_7 [ var_9 ] ) { var_5 = var_7 [ var_9 ] ; var_6 = var_8 [ var_9 ] ; } } return var_6 ; }
286
<awangdev>Best Time to Buy and Sell Stock with Transaction Fee_1.java
public int maxProfit(int[] prices, int fee) { if (prices == null || prices.length <= 1) return 0; int n = prices.length; int[][] dp = new int[n + 1][2]; dp[0][0] = dp[0][1] = 0; dp[1][1] = 0; dp[1][0] = - prices[0]; for (int i = 2; i <= n; i++) { dp[i][0] = Math.max(dp[i-1][0], dp[i - 1][1] - prices[i - 1]); dp[i][1] = Math.max(dp[i-1][1], dp[i - 1][0] + prices[i - 1] - fee); } return dp[n][1]; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length <= 1 ) return 0 ; int var_6 = var_0 . length ; int [ ] [ ] var_8 = new int [ var_6 + 1 ] [ 2 ] ; var_8 [ 0 ] [ 0 ] = var_8 [ 0 ] [ 1 ] = 0 ; var_8 [ 1 ] [ 1 ] = 0 ; var_8 [ 1 ] [ 0 ] = - var_0 [ 0 ] ; for ( int var_9 = 2 ; var_9 <= var_6 ; var_9 ++ ) { var_8 [ var_9 ] [ 0 ] = Math . max ( var_8 [ var_9 - 1 ] [ 0 ] , var_8 [ var_9 - 1 ] [ 1 ] - var_0 [ var_9 - 1 ] ) ; var_8 [ var_9 ] [ 1 ] = Math . max ( var_8 [ var_9 - 1 ] [ 1 ] , var_8 [ var_9 - 1 ] [ 0 ] + var_0 [ var_9 - 1 ] - var_1 ) ; } return var_8 [ var_6 ] [ 1 ] ; }
287
<awangdev>1213. Intersection of Three Sorted Arrays_2.java
public List<Integer> arraysIntersection(int[] arr1, int[] arr2, int[] arr3) { List<Integer> rst = new LinkedList<>(); int i = arr1.length - 1, j = arr2.length - 1, k = arr3.length - 1; while (i >= 0 && j >= 0 && k >= 0) { if (arr1[i] == arr2[j] && arr2[j] == arr3[k]) { if (rst.isEmpty() || arr1[i] != rst.get(rst.size() - 1)) rst.add(0, arr1[i]); i--; j--; k--; } else if (arr2[j] < arr3[k]) k--; else if (arr1[i] < arr2[j]) j--; else i--; } return rst; }
public List < Integer > var_1 ( int [ ] var_2 , int [ ] var_3 , int [ ] var_4 ) { List < Integer > var_7 = new LinkedList < > ( ) ; int var_10 = var_2 . length - 1 , var_11 = var_3 . length - 1 , var_12 = var_4 . length - 1 ; while ( var_10 >= 0 && var_11 >= 0 && var_12 >= 0 ) { if ( var_2 [ var_10 ] == var_3 [ var_11 ] && var_3 [ var_11 ] == var_4 [ var_12 ] ) { if ( var_7 . isEmpty ( ) || var_2 [ var_10 ] != var_7 . get ( var_7 . size ( ) - 1 ) ) var_7 . add ( 0 , var_2 [ var_10 ] ) ; var_10 -- ; var_11 -- ; var_12 -- ; } else if ( var_3 [ var_11 ] < var_4 [ var_12 ] ) var_12 -- ; else if ( var_2 [ var_10 ] < var_3 [ var_11 ] ) var_11 -- ; else var_10 -- ; } return var_7 ; }
288
<awangdev>Convert Integer A to Integer B_1.java
public static int bitSwapRequired(int a, int b) { int count = 0; for (int i = 0; i < 32; i++) { count += (a ^ b) >> i & 1; } return count; }
public static int sample_funcname ( int var_0 , int var_1 ) { int var_3 = 0 ; for ( int var_4 = 0 ; var_4 < 32 ; var_4 ++ ) { var_3 += ( var_0 ^ var_1 ) >> var_4 & 1 ; } return var_3 ; }
289
<awangdev>Count 1 in Binary_1.java
public int countOnes(int num) { int count = 0; for (int i = 1; i <= 32; i++) { count += num >> i & 1; } return count; }
public int sample_funcname ( int var_0 ) { int var_2 = 0 ; for ( int var_4 = 1 ; var_4 <= 32 ; var_4 ++ ) { var_2 += var_0 >> var_4 & 1 ; } return var_2 ; }
290
<awangdev>463. Island Perimeter_1.java
private boolean validate(int[][] grid, int x, int y) { return x >= 0 && y >= 0 && x < grid.length && y < grid[0].length && grid[x][y] == 1; }
private boolean var_0 ( int [ ] [ ] var_1 , int var_2 , int var_3 ) { return var_2 >= 0 && var_3 >= 0 && var_2 < var_1 . length && var_3 < var_1 [ 0 ] . length && var_1 [ var_2 ] [ var_3 ] == 1 ; }
291
<awangdev>43. Multiply Strings_3.java
private char toChar(int num) { return (char)(num + '0'); }
private char sample_funcname ( int var_0 ) { return ( char ) ( var_0 + '0' ) ; }
292
<awangdev>136. Single Number_1.java
public int singleNumber(int[] nums) { if (nums == null || nums.length == 0) return 0; int result = 0; for (int i : nums) { result = result ^ i; } return result; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = 0 ; for ( int var_5 : var_0 ) { var_4 = var_4 ^ var_5 ; } return var_4 ; }
293
<awangdev>Letter Combinations of a Phone Number_2.java
public void helper(ArrayList<String> rst, ArrayList<String> list, ArrayList<String[]> map, String digits, int level){ if (level == digits.length()) { StringBuffer sb = new StringBuffer(); for (String s : list) { sb.append(s); } rst.add(sb.toString()); return; } int num = Integer.parseInt(digits.substring(level, level + 1)); String[] strs = map.get(num); for (int i = 0; i < strs.length; i++) { list.add(strs[i]); helper(rst, list, map, digits, level + 1); list.remove(list.size() - 1); } }
public void sample_funcname ( ArrayList < String > rst , ArrayList < String > list , ArrayList < String [ ] > map , String digits , int level ) { if ( level == digits . length ( ) ) { StringBuffer sb = new StringBuffer ( ) ; for ( String s : list ) { sb . append ( s ) ; } rst . add ( sb . toString ( ) ) ; return ; } int num = Integer . parseInt ( digits . substring ( level , level + 1 ) ) ; String [ ] strs = map . get ( num ) ; for ( int i = 0 ; i < strs . length ; i ++ ) { list . add ( strs [ i ] ) ; helper ( rst , list , map , digits , level + 1 ) ; list . remove ( list . size ( ) - 1 ) ; } }
294
<awangdev>O(1) Check Power of 2_1.java
public boolean checkPowerOf2(int n) { if (n <= 0) { return false; } return (n & (n - 1)) == 0; }
public boolean var_0 ( int var_1 ) { if ( var_1 <= 0 ) { return false ; } return ( var_1 & ( var_1 - 1 ) ) == 0 ; }
295
<awangdev>Longest Common Subsequence_1.java
public int longestCommonSubsequence(String A, String B) { if (A == null || B == null || A.length() == 0 || B.length() == 0) { return 0; } int m = A.length(); int n = B.length(); int[][] dp = new int[m + 1][n + 1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; continue; } dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]); if (A.charAt(i - 1) == B.charAt(j - 1)) { dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - 1] + 1); } } } return dp[m][n]; }
public int sample_funcname ( String var_1 , String var_2 ) { if ( var_1 == null || var_2 == null || var_1 . length ( ) == 0 || var_2 . length ( ) == 0 ) { return 0 ; } int var_6 = var_1 . length ( ) ; int var_7 = var_2 . length ( ) ; int [ ] [ ] var_9 = new int [ var_6 + 1 ] [ var_7 + 1 ] ; for ( int var_10 = 0 ; var_10 <= var_6 ; var_10 ++ ) { for ( int var_11 = 0 ; var_11 <= var_7 ; var_11 ++ ) { if ( var_10 == 0 || var_11 == 0 ) { var_9 [ var_10 ] [ var_11 ] = 0 ; continue ; } var_9 [ var_10 ] [ var_11 ] = Math . max ( var_9 [ var_10 - 1 ] [ var_11 ] , var_9 [ var_10 ] [ var_11 - 1 ] ) ; if ( var_1 . charAt ( var_10 - 1 ) == var_2 . charAt ( var_11 - 1 ) ) { var_9 [ var_10 ] [ var_11 ] = Math . max ( var_9 [ var_10 ] [ var_11 ] , var_9 [ var_10 - 1 ] [ var_11 - 1 ] + 1 ) ; } } } return var_9 [ var_6 ] [ var_7 ] ; }
296
<awangdev>Longest Increasing Path in a Matrix_1.java
private boolean validateCoordinate(int[][] matrix, int x, int y, int nx, int ny) { return nx >= 0 && nx < matrix.length && ny >= 0 && ny < matrix[0].length && matrix[x][y] < matrix[nx][ny]; }
private boolean var_0 ( int [ ] [ ] var_1 , int var_2 , int var_3 , int var_4 , int var_5 ) { return var_4 >= 0 && var_4 < var_1 . length && var_5 >= 0 && var_5 < var_1 [ 0 ] . length && var_1 [ var_2 ] [ var_3 ] < var_1 [ var_4 ] [ var_5 ] ; }
297
<awangdev>921. Minimum Add to Make Parentheses Valid_2.java
public int minAddToMakeValid(String s) { if (s == null || s.length() == 0) { return 0; } int count = 0, openCount = 0; for (char c : s.toCharArray()) { if (c == '(') openCount++; else if (openCount == 0) count++; else openCount--; } return count + openCount; }
public int sample_funcname ( String var_1 ) { if ( var_1 == null || var_1 . length ( ) == 0 ) { return 0 ; } int var_5 = 0 , var_6 = 0 ; for ( char var_8 : var_1 . toCharArray ( ) ) { if ( var_8 == '(' ) var_6 ++ ; else if ( var_6 == 0 ) var_5 ++ ; else var_6 -- ; } return var_5 + var_6 ; }
298
<awangdev>The Maze II_1.java
private String getKey(int x, int y){ return x + "@" + y; }
private String var_0 ( int var_1 , int var_2 ) { return var_1 + "@" + var_2 ; }
299
<awangdev>239. Sliding Window Maximum_4.java
private void outQueue(Deque<Integer> deque, int num) { if (deque.peekFirst() == num) deque.pollFirst(); }
private void var_0 ( Deque < Integer > var_3 , int var_4 ) { if ( var_3 . peekFirst ( ) == var_4 ) var_3 . pollFirst ( ) ; }