id
int64
0
1.17k
comefrom
stringlengths
21
84
code
stringlengths
50
1.89k
masked
stringlengths
63
2.42k
unique_words_num
int64
0
6
words
stringlengths
1
139
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_2 = var_0 . length ; int [ ] var_3 = new int [ var_1 + 1 ] ; var_3 [ 0 ] = 1 ; for ( int var_4 = 1 ; var_4 <= var_1 ; var_4 ++ ) { var_3 [ var_4 ] = 0 ; } for ( int var_5 = 1 ; var_5 <= var_2 ; var_5 ++ ) { for ( int var_4 = var_1 ; var_4 >= 0 ; var_4 -- ) { if ( var_4 - var_0 [ var_5 - 1 ] >= 0 ) { var_3 [ var_4 ] += var_3 [ var_4 - var_0 [ var_5 - 1 ] ] ; } } } return var_3 [ var_1 ] ; }
2
0<SEP>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_1 , Map < Character , Integer > var_2 , int var_3 ) { for ( int var_4 = 0 ; var_4 < var_1 . length ( ) ; var_4 ++ ) { char var_5 = var_1 . charAt ( var_4 ) ; var_2 . putIfAbsent ( var_5 , 0 ) ; var_2 . put ( var_5 , var_2 . get ( var_5 ) + var_3 ) ; } }
1
0
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 ; }
0
null
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 ; }
0
null
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_1 , String var_2 , int [ ] var_3 ) { if ( var_1 . indexOf ( var_2 ) >= 0 ) return false ; int var_4 = Math . min ( var_1 . length ( ) , var_2 . length ( ) ) ; for ( int var_5 = 0 ; var_5 < var_4 ; var_5 ++ ) { int var_6 = var_1 . charAt ( var_5 ) , var_7 = var_2 . charAt ( var_5 ) ; if ( var_3 [ var_6 ] == var_3 [ var_7 ] ) continue ; return var_3 [ var_6 ] < var_3 [ var_7 ] ; } return true ; }
1
0
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_1 = var_0 [ 0 ] , var_2 = var_0 [ var_0 [ 0 ] ] ; while ( var_1 != var_2 ) { var_1 = var_0 [ var_1 ] ; var_2 = var_0 [ var_0 [ var_2 ] ] ; } int var_3 = 0 ; while ( var_1 != var_3 ) { var_1 = var_0 [ var_1 ] ; var_3 = var_0 [ var_3 ] ; } return var_1 ; }
1
0
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_3 = new int [ var_1 . length + 1 ] [ var_0 + 1 ] ; var_3 [ 0 ] [ 0 ] = 0 ; for ( int var_4 = 1 ; var_4 <= var_1 . length ; var_4 ++ ) { for ( int var_5 = 0 ; var_5 <= var_0 ; var_5 ++ ) { if ( var_5 - var_1 [ var_4 - 1 ] >= 0 ) { var_3 [ var_4 ] [ var_5 ] = Math . max ( var_3 [ var_4 - 1 ] [ var_5 ] , var_3 [ var_4 - 1 ] [ var_5 - var_1 [ var_4 - 1 ] ] + var_2 [ var_4 - 1 ] ) ; } else { var_3 [ var_4 ] [ var_5 ] = var_3 [ var_4 - 1 ] [ var_5 ] ; } } } return var_3 [ var_1 . length ] [ var_0 ] ; }
2
0<SEP>1
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_2 = var_1 . length ; int [ ] [ ] var_3 = new int [ var_2 ] [ var_2 ] ; for ( int var_4 = 0 ; var_4 < var_2 ; var_4 ++ ) { var_3 [ var_4 ] [ var_4 ] = var_1 [ var_4 ] ; } for ( int var_5 = 2 ; var_5 <= var_2 ; var_5 ++ ) { for ( int var_4 = 0 ; var_4 <= var_2 - var_5 ; var_4 ++ ) { int var_6 = var_5 + var_4 - 1 ; var_3 [ var_4 ] [ var_6 ] = Math . max ( var_1 [ var_4 ] - var_3 [ var_4 + 1 ] [ var_6 ] , var_1 [ var_6 ] - var_3 [ var_4 ] [ var_6 - 1 ] ) ; } } return var_3 [ 0 ] [ var_2 - 1 ] >= 0 ; }
3
0<SEP>1<SEP>2
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 ; } }
2
0<SEP>1
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 ) ; } }
2
0<SEP>1
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_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return "" ; } Arrays . sort ( var_1 ) ; String var_2 = var_1 [ 0 ] ; String var_3 = var_1 [ var_1 . length - 1 ] ; int var_4 = var_2 . length ( ) < var_3 . length ( ) ? var_2 . length ( ) : var_3 . length ( ) ; StringBuffer var_5 = new StringBuffer ( ) ; for ( int var_6 = 0 ; var_6 < var_4 ; var_6 ++ ) { if ( var_2 . charAt ( var_6 ) != var_3 . charAt ( var_6 ) ) { break ; } var_5 . append ( var_2 . charAt ( var_6 ) ) ; } return var_5 . toString ( ) ; }
3
0<SEP><D_QUOTE><D_QUOTE><SEP>1
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_1 = var_0 . length ; int [ ] var_2 = new int [ var_1 ] ; var_2 [ 0 ] = 0 ; for ( int var_3 = 1 ; var_3 < var_1 ; var_3 ++ ) { var_2 [ var_3 ] = Integer . MAX_VALUE ; for ( int var_4 = 0 ; var_4 < var_3 ; var_4 ++ ) { if ( var_4 + var_0 [ var_4 ] >= var_3 ) var_2 [ var_3 ] = Math . min ( var_2 [ var_3 ] , var_2 [ var_4 ] + 1 ) ; } } return var_2 [ var_1 - 1 ] ; }
2
0<SEP>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_1 , int [ ] var_2 , int var_3 ) { int var_4 = var_3 - var_2 [ var_3 ] , var_5 = var_3 + var_2 [ var_3 ] ; if ( var_4 >= 0 ) var_1 . offer ( var_4 ) ; if ( var_5 < var_2 . length ) var_1 . offer ( var_5 ) ; }
1
0
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_1 , String var_2 ) { if ( var_1 == null || var_1 . length ( ) == 0 || var_2 == null || var_2 . length ( ) == 0 ) { return false ; } String [ ] var_3 = var_2 . split ( " " ) ; if ( var_1 . length ( ) != var_3 . length ) { return false ; } HashMap < Character , String > var_4 = new HashMap < Character , String > ( ) ; for ( int var_5 = 0 ; var_5 < var_1 . length ( ) ; var_5 ++ ) { char var_6 = var_1 . charAt ( var_5 ) ; String var_7 = var_3 [ var_5 ] ; if ( ! var_4 . containsKey ( var_6 ) ) { if ( var_4 . containsValue ( var_7 ) ) { return false ; } var_4 . put ( var_6 , var_7 ) ; } else if ( ! var_4 . get ( var_6 ) . equals ( var_7 ) ) { return false ; } } return true ; }
2
0<SEP><D_QUOTE> <D_QUOTE>
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_1 = 0 , var_2 = var_0 . length ; int [ ] min = new int [ var_2 ] ; min [ 0 ] = var_0 [ 0 ] ; for ( int var_3 = 1 ; var_3 < var_2 ; var_3 ++ ) { min [ var_3 ] = Math . min ( min [ var_3 - 1 ] , var_0 [ var_3 ] ) ; var_1 = Math . max ( var_1 , var_0 [ var_3 ] - min [ var_3 ] ) ; } return var_1 ; }
2
1<SEP>0
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' ; }
2
0<SEP><S_QUOTE>0<S_QUOTE>
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_1 , String var_2 ) { if ( var_1 == null || var_2 == null || var_1 . equals ( var_2 ) || Math . abs ( var_1 . length ( ) - var_2 . length ( ) ) > 1 ) { return false ; } int var_3 = var_1 . length ( ) > var_2 . length ( ) ? var_2 . length ( ) : var_1 . length ( ) ; for ( int var_4 = 0 ; var_4 < var_3 ; var_4 ++ ) { if ( var_1 . charAt ( var_4 ) != var_2 . charAt ( var_4 ) ) { if ( var_1 . substring ( var_4 + 1 ) . equals ( var_2 . substring ( var_4 ) ) || var_1 . substring ( var_4 ) . equals ( var_2 . substring ( var_4 + 1 ) ) ) { return true ; } return var_1 . substring ( var_4 + 1 ) . equals ( var_2 . substring ( var_4 + 1 ) ) ; } } return true ; }
2
1<SEP>0
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 ; }
1
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_1 = new int [ var_0 ] ; var_1 [ 0 ] = 0 ; var_1 [ 1 ] = 1 ; for ( int var_2 = 2 ; var_2 < var_0 ; var_2 ++ ) { var_1 [ var_2 ] = var_1 [ var_2 - 1 ] + var_1 [ var_2 - 2 ] ; } return var_1 [ var_0 - 1 ] ; }
3
1<SEP>0<SEP>2
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_2 = var_1 . length ; boolean [ ] var_3 = new boolean [ var_2 ] ; var_3 [ 0 ] = true ; for ( int var_4 = 1 ; var_4 < var_2 ; var_4 ++ ) { var_3 [ var_4 ] = false ; for ( int var_5 = 0 ; var_5 < var_4 ; var_5 ++ ) { if ( var_3 [ var_5 ] && var_5 + var_1 [ var_5 ] >= var_4 ) { var_3 [ var_4 ] = true ; break ; } } } return var_3 [ var_2 - 1 ] ; }
2
0<SEP>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_1 = var_0 . length ; int var_2 = 0 ; int var_3 = var_0 . length - 1 ; int var_4 = 0 ; while ( var_2 <= var_3 ) { var_4 = var_2 + ( var_3 - var_2 ) / 2 ; if ( ( var_4 - 1 < 0 || var_0 [ var_4 ] > var_0 [ var_4 - 1 ] ) && ( var_4 + 1 >= var_1 || var_0 [ var_4 ] > var_0 [ var_4 + 1 ] ) ) { return var_4 ; } else if ( var_4 - 1 >= 0 && var_0 [ var_4 ] < var_0 [ var_4 - 1 ] ) { var_3 = var_4 - 1 ; } else { var_2 = var_4 + 1 ; } } return var_4 ; }
3
1<SEP>0<SEP>2
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_0 ) { if ( var_0 == null || var_0 . size ( ) == 0 ) return Integer . MAX_VALUE ; int var_1 = 0 , min = Integer . MAX_VALUE ; for ( int var_2 : var_0 ) { var_1 = Math . min ( var_2 , var_1 + var_2 ) ; min = Math . min ( min , var_1 ) ; } return min ; }
1
0
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_1 , String var_2 ) { if ( var_1 == null || var_2 == null ) { return false ; } else if ( Math . abs ( var_1 . length ( ) - var_2 . length ( ) ) > 1 || var_1 . equals ( var_2 ) ) { return false ; } int var_3 = var_1 . length ( ) > var_2 . length ( ) ? var_2 . length ( ) : var_1 . length ( ) ; for ( int var_4 = 0 ; var_4 < var_3 ; var_4 ++ ) { String var_5 = var_1 ; String var_6 = var_2 ; if ( var_1 . charAt ( var_4 ) != var_2 . charAt ( var_4 ) ) { var_6 = var_2 . substring ( var_4 + 1 ) ; var_5 = var_1 . substring ( var_4 ) ; if ( var_6 . equals ( var_5 ) ) { return true ; } var_6 = var_2 . substring ( var_4 ) ; var_5 = var_1 . substring ( var_4 + 1 ) ; if ( var_6 . equals ( var_5 ) ) { return true ; } var_5 = var_1 . substring ( 0 , var_4 ) + var_1 . substring ( var_4 + 1 ) ; var_6 = var_2 . substring ( 0 , var_4 ) + var_2 . substring ( var_4 + 1 ) ; return var_5 . equals ( var_6 ) ; } } return true ; }
2
1<SEP>0
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_2 = 0 ; for ( int var_3 = 0 ; var_3 < var_1 ; var_3 ++ ) { var_2 += var_0 [ var_3 ] ; } double max = var_2 ; for ( int var_3 = var_1 ; var_3 < var_0 . length ; var_3 ++ ) { max = Math . max ( var_2 , max ) ; var_2 = var_2 - var_0 [ var_3 - var_1 ] + var_0 [ var_3 ] ; } max = Math . max ( var_2 , max ) ; return max / var_1 ; }
1
0
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 ) ; } }
2
1<SEP>0
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_2 = var_1 . length , var_3 = var_2 - 1 ; for ( int var_4 = var_3 ; var_4 >= 0 ; var_4 -- ) { if ( var_4 + var_1 [ var_4 ] >= var_3 ) var_3 = var_4 ; } return var_3 == 0 ; }
2
0<SEP>1
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_1 = var_0 . length ; int var_2 = 0 ; int var_3 = var_1 - 1 ; while ( var_2 + 1 < var_3 ) { int var_4 = ( var_2 + var_3 ) >> 1 ; if ( var_0 [ var_4 ] > var_0 [ var_4 - 1 ] && var_0 [ var_4 ] > var_0 [ var_4 + 1 ] ) { return var_4 ; } else if ( var_0 [ var_4 ] > var_0 [ var_4 - 1 ] ) { var_2 = var_4 ; } else { var_3 = var_4 ; } } return var_0 [ var_2 ] > var_0 [ var_3 ] ? var_2 : var_3 ; }
2
0<SEP>1
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 ) ; }
3
1<SEP>0<SEP>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_1 = var_0 . length ; int var_2 = 0 , var_3 = 0 , var_4 = 0 ; while ( var_3 < var_1 - 1 ) { var_4 ++ ; int var_5 = 0 ; for ( int var_6 = var_2 ; var_6 <= var_3 ; var_6 ++ ) { var_5 = Math . max ( var_5 , var_6 + var_0 [ var_6 ] ) ; if ( var_5 >= var_1 - 1 ) { return var_4 ; } } var_2 = var_3 + 1 ; var_3 = var_5 ; } return 0 ; }
2
0<SEP>1
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_0 ) { if ( var_0 == null || var_0 . length ( ) == 0 ) { return 0 ; } int var_1 = 0 ; for ( char var_2 : var_0 . toCharArray ( ) ) { int var_3 = var_2 - 'A' + 1 ; var_1 = var_1 * 26 + var_3 ; } return var_1 ; }
4
0<SEP>26<SEP>1<SEP><S_QUOTE>A<S_QUOTE>
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' ; }
2
0<SEP><S_QUOTE>1<S_QUOTE>
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_1 = 0 , max = Integer . MIN_VALUE ; for ( int var_2 : var_0 ) { var_1 = Math . max ( var_2 , var_1 + var_2 ) ; max = Math . max ( max , var_1 ) ; } return max ; }
1
0
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_3 = new HashSet < > ( ) ; int var_4 = 0 ; for ( int var_5 : var_1 ) { int var_6 = ( var_4 + var_5 ) % var_2 ; if ( var_3 . contains ( var_6 ) ) return true ; var_3 . add ( var_4 ) ; var_4 = var_6 ; } return false ; }
2
0<SEP>2
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_2 = 0 , var_3 = var_0 . length - 1 ; int var_4 = var_0 [ var_3 ] - var_0 [ 0 ] - var_3 ; if ( var_4 < var_1 ) { return var_0 [ var_3 ] + var_1 - var_4 ; } while ( var_2 + 1 < var_3 ) { int var_5 = var_2 + ( var_3 - var_2 ) / 2 ; var_4 = var_0 [ var_5 ] - var_0 [ 0 ] - var_5 ; if ( var_4 >= var_1 ) var_3 = var_5 ; else var_2 = var_5 ; } var_4 = var_0 [ var_2 ] - var_0 [ 0 ] - var_2 ; return var_0 [ var_2 ] + var_1 - var_4 ; }
3
2<SEP>0<SEP>1
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_1 = 0 , min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ; for ( int var_2 : var_0 ) { min = Math . min ( min , var_2 ) ; max = Math . max ( max , var_2 ) ; } if ( min < 0 ) { var_1 = Math . abs ( min ) ; max += var_1 ; min += var_1 ; } return new int [ ] { min , max , var_1 }; }
1
0
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_1 = var_0 . length ; int [ ] var_2 = new int [ var_1 + 2 ] ; var_2 [ 0 ] = 1 ; var_2 [ var_1 + 1 ] = 1 ; for ( int var_3 = 1 ; var_3 <= var_1 ; var_3 ++ ) { var_2 [ var_3 ] = var_0 [ var_3 - 1 ] ; } var_1 = var_2 . length ; int [ ] [ ] var_4 = new int [ var_1 ] [ var_1 ] ; for ( int var_5 = 3 ; var_5 <= var_1 ; var_5 ++ ) { for ( int var_3 = 0 ; var_3 <= var_1 - var_5 ; var_3 ++ ) { int var_6 = var_5 + var_3 - 1 ; for ( int var_7 = var_3 + 1 ; var_7 < var_6 ; var_7 ++ ) { var_4 [ var_3 ] [ var_6 ] = Math . max ( var_4 [ var_3 ] [ var_6 ] , var_4 [ var_3 ] [ var_7 ] + var_4 [ var_7 ] [ var_6 ] + var_2 [ var_3 ] * var_2 [ var_7 ] * var_2 [ var_6 ] ) ; } } } return var_4 [ 0 ] [ var_1 - 1 ] ; }
4
0<SEP>3<SEP>1<SEP>2
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_3 = new PriorityQueue < > ( Comparator . comparing ( var_2 -> var_2 [ 0 ] ) ) ; for ( int [ ] var_4 : var_1 ) { var_3 . offer ( new int [ ] { var_4 [ 1 ] , var_4 [ 0 ] } ) ; var_3 . offer ( new int [ ] { var_4 [ 2 ] , - var_4 [ 0 ] } ) ; } return var_3 ; }
3
2<SEP>0<SEP>1
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 ; }
0
null
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_2 = var_0 [ 0 ] + var_0 [ 1 ] + var_0 [ 2 ] ; for ( int var_3 = 0 ; var_3 < var_0 . length - 2 ; var_3 ++ ) { int var_4 = var_3 + 1 ; int var_5 = var_0 . length - 1 ; while ( var_4 < var_5 ) { long var_6 = var_0 [ var_4 ] + var_0 [ var_5 ] + var_0 [ var_3 ] ; if ( var_6 > var_1 ) { var_5 -- ; } else { var_4 ++ ; } var_2 = Math . abs ( var_6 - var_1 ) < Math . abs ( var_2 - var_1 ) ? var_6 : var_2 ; } } return ( int ) var_2 ; }
4
2<SEP>0<SEP>3<SEP>1
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_1 , String var_2 ) { if ( var_1 == null || var_2 == null || var_1 . length ( ) != var_2 . length ( ) ) { return false ; } if ( var_1 . equals ( var_2 ) ) { return true ; } HashMap < String , Integer > var_3 = new HashMap < String , Integer > ( ) ; for ( int var_4 = 0 ; var_4 < var_1 . length ( ) ; var_4 ++ ) { String var_5 = var_1 . substring ( var_4 , var_4 + 1 ) ; String var_6 = var_2 . substring ( var_4 , var_4 + 1 ) ; if ( ! var_3 . containsKey ( var_5 ) ) { var_3 . put ( var_5 , 0 ) ; } var_3 . put ( var_5 , var_3 . get ( var_5 ) + 1 ) ; if ( ! var_3 . containsKey ( var_6 ) ) { var_3 . put ( var_6 , 0 ) ; } var_3 . put ( var_6 , var_3 . get ( var_6 ) - 1 ) ; } for ( Map . Entry < String , Integer > var_7 : var_3 . entrySet ( ) ) { if ( var_7 . getValue ( ) != 0 ) { return false ; } } return true ; }
2
0<SEP>1
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_2 = 0 , var_3 = var_0 . length - 1 ; while ( var_2 + 1 < var_3 ) { int var_4 = var_2 + ( var_3 - var_2 ) / 2 ; if ( var_0 [ var_4 ] == var_1 ) return var_4 ; if ( var_0 [ var_2 ] < var_0 [ var_4 ] ) { if ( var_0 [ var_2 ] <= var_1 && var_1 <= var_0 [ var_4 ] ) var_3 = var_4 ; else var_2 = var_4 ; } else { if ( var_0 [ var_4 ] <= var_1 && var_1 <= var_0 [ var_3 ] ) var_2 = var_4 ; else var_3 = var_4 ; } } if ( var_0 [ var_2 ] == var_1 ) return var_2 ; if ( var_0 [ var_3 ] == var_1 ) return var_3 ; return - 1 ; }
3
2<SEP>0<SEP>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_3 = var_1 . length ; int [ ] [ ] var_4 = new int [ 2 ] [ var_0 + 1 ] ; var_4 [ 0 ] [ 0 ] = 0 ; for ( int var_5 = 0 ; var_5 <= var_0 ; var_5 ++ ) { var_4 [ 0 ] [ var_5 ] = 0 ; } int var_6 = 0 , var_7 ; for ( int var_8 = 1 ; var_8 <= var_3 ; var_8 ++ ) { var_7 = var_6 ; var_6 = 1 - var_7 ; for ( int var_5 = 1 ; var_5 <= var_0 ; var_5 ++ ) { var_4 [ var_6 ] [ var_5 ] = var_4 [ var_7 ] [ var_5 ] ; if ( var_5 - var_1 [ var_8 - 1 ] >= 0 ) { var_4 [ var_6 ] [ var_5 ] = Math . max ( var_4 [ var_6 ] [ var_5 ] , var_4 [ var_7 ] [ var_5 - var_1 [ var_8 - 1 ] ] + var_2 [ var_8 - 1 ] ) ; } } } return var_4 [ var_6 ] [ var_0 ] ; }
3
0<SEP>1<SEP>2
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 ; }
0
null
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_0 , String var_1 ) { if ( var_0 . equals ( var_1 ) ) { return 0 ; } while ( var_0 != null && var_0 . length ( ) > 1 && var_0 . charAt ( 0 ) == '0' ) { var_0 = var_0 . substring ( 1 ) ; } while ( var_1 != null && var_1 . length ( ) > 1 && var_1 . charAt ( 0 ) == '0' ) { var_1 = var_1 . substring ( 1 ) ; } if ( var_0 . length ( ) != var_1 . length ( ) ) { return var_0 . length ( ) < var_1 . length ( ) ? - 1 : 1 ; } for ( int var_2 = 0 ; var_2 < var_0 . length ( ) ; var_2 ++ ) { int var_3 = var_0 . charAt ( var_2 ) - '0' ; int var_4 = var_1 . charAt ( var_2 ) - '0' ; if ( var_3 < var_4 ) { return - 1 ; } else if ( var_3 > var_4 ) { return 1 ; } } return 0 ; }
3
0<SEP><S_QUOTE>0<S_QUOTE><SEP>1
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_2 = var_0 . length ; int [ ] [ ] var_3 = new int [ 2 ] [ var_1 + 1 ] ; var_3 [ 0 ] [ 0 ] = 1 ; for ( int var_4 = 1 ; var_4 <= var_1 ; var_4 ++ ) { var_3 [ 0 ] [ var_4 ] = 0 ; } int var_5 = 0 , var_6 = 1 ; for ( int var_7 = 1 ; var_7 <= var_2 ; var_7 ++ ) { var_6 = var_5 ; var_5 = 1 - var_5 ; for ( int var_4 = 0 ; var_4 <= var_1 ; var_4 ++ ) { var_3 [ var_5 ] [ var_4 ] = var_3 [ var_6 ] [ var_4 ] ; if ( var_4 - var_0 [ var_7 - 1 ] >= 0 ) { var_3 [ var_5 ] [ var_4 ] += var_3 [ var_6 ] [ var_4 - var_0 [ var_7 - 1 ] ] ; } } } return var_3 [ var_5 ] [ var_1 ] ; }
3
0<SEP>1<SEP>2
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_1 ) { if ( var_1 == null || var_1 . length ( ) <= 1 ) { return var_1 ; } char [ ] var_2 = var_1 . toCharArray ( ) ; int [ ] var_3 = new int [ 256 ] ; boolean [ ] var_4 = new boolean [ 256 ] ; for ( char var_5 : var_2 ) { var_3 [ var_5 ] ++ ; } Stack < Character > var_6 = new Stack < > ( ) ; var_6 . push ( '0' ) ; for ( char var_5 : var_2 ) { var_3 [ var_5 ] -- ; if ( var_4 [ var_5 ] ) { continue ; } while ( var_5 < var_6 . peek ( ) && var_3 [ var_6 . peek ( ) ] > 0 ) { var_4 [ var_6 . pop ( ) ] = false ; } var_6 . push ( var_5 ) ; var_4 [ var_5 ] = true ; } StringBuffer var_7 = new StringBuffer ( ) ; while ( ! var_6 . isEmpty ( ) ) { var_7 . insert ( 0 , var_6 . pop ( ) ) ; } return var_7 . substring ( 1 ) . toString ( ) ; }
4
<S_QUOTE>0<S_QUOTE><SEP>1<SEP>0<SEP>256
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_4 = var_3 [ 2 ] - var_3 [ 0 ] - 2 ; if ( var_3 [ 2 ] - var_3 [ 0 ] == 2 ) return new int [ ] { 0 , var_4 }; if ( var_3 [ 1 ] - var_3 [ 0 ] <= 2 || var_3 [ 2 ] - var_3 [ 1 ] <= 2 ) return new int [ ] { 1 , var_4 }; return new int [ ] { 2 , var_4 }; }
3
0<SEP>1<SEP>2
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_1 ) { if ( var_1 . equals ( "+" ) || var_1 . equals ( "-" ) ) { return var_0 + 1 ; } if ( var_1 . equals ( "*" ) || var_1 . equals ( "/" ) ) { return var_0 + 2 ; } return Integer . MAX_VALUE ; }
6
<D_QUOTE>-<D_QUOTE><SEP>2<SEP><D_QUOTE>/<D_QUOTE><SEP>1<SEP><D_QUOTE>+<D_QUOTE><SEP><D_QUOTE>*<D_QUOTE>
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_2 , var_3 , var_4 ; var_2 = var_3 = var_4 = 0 ; int min = Integer . MAX_VALUE ; while ( var_3 < var_1 . length ) { while ( var_4 < var_0 && var_3 < var_1 . length ) { var_4 += var_1 [ var_3 ] ; var_3 ++ ; } while ( var_4 >= var_0 && var_2 >= 0 ) { min = Math . min ( min , var_3 - var_2 ) ; var_4 -= var_1 [ var_2 ] ; var_2 ++ ; } } return min == Integer . MAX_VALUE ? 0 : min ; }
1
0
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_2 = 0 ; while ( var_2 < var_1 . length - 1 ) { var_2 += var_1 [ var_2 ] % 2 == 1 ? 2 : 1 ; } return var_2 == var_1 . length - 1 ; }
3
2<SEP>0<SEP>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_2 = 0 ; int var_3 = var_1 . length - 1 ; if ( var_1 . length % 2 != 0 ) { if ( var_1 [ ( var_2 + var_3 ) / 2 ] >= 0 ) { var_3 -- ; } else { var_2 ++ ; } } while ( var_2 < var_3 ) { int var_4 = var_1 [ var_2 ] ; var_1 [ var_2 ] = var_1 [ var_3 ] ; var_1 [ var_3 ] = var_4 ; var_2 += 2 ; var_3 -= 2 ; } }
3
1<SEP>0<SEP>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_0 ) { if ( var_0 == null || var_0 . size ( ) == 0 ) { return 0 ; } int [ ] var_1 = new int [ var_0 . size ( ) ] ; int [ ] var_2 = new int [ var_0 . size ( ) ] ; int var_3 = 0 ; var_1 [ 0 ] = var_0 . get ( 0 ) ; for ( int var_4 = 1 ; var_4 < var_1 . length ; var_4 ++ ) { if ( var_1 [ var_4 - 1 ] < 0 ) { var_1 [ var_4 ] = var_0 . get ( var_4 ) ; } else { var_1 [ var_4 ] = var_1 [ var_4 - 1 ] + var_0 . get ( var_4 ) ; } } var_3 = var_1 [ 0 ] ; for ( int var_4 = 1 ; var_4 < var_1 . length ; var_4 ++ ) { if ( var_1 [ var_4 ] < var_3 ) { var_1 [ var_4 ] = var_3 ; } else { var_3 = var_1 [ var_4 ] ; } } var_2 [ var_2 . length - 1 ] = var_0 . get ( var_0 . size ( ) - 1 ) ; for ( int var_4 = var_2 . length - 2 ; var_4 >= 0 ; var_4 -- ) { if ( var_2 [ var_4 + 1 ] < 0 ) { var_2 [ var_4 ] = var_0 . get ( var_4 ) ; } else { var_2 [ var_4 ] = var_2 [ var_4 + 1 ] + var_0 . get ( var_4 ) ; } } var_3 = var_2 [ var_2 . length - 1 ] ; for ( int var_4 = var_2 . length - 2 ; var_4 >= 0 ; var_4 -- ) { if ( var_2 [ var_4 ] < var_3 ) { var_2 [ var_4 ] = var_3 ; } else { var_3 = var_2 [ var_4 ] ; } } var_3 = Integer . MIN_VALUE ; for ( int var_4 = 0 ; var_4 < var_0 . size ( ) - 1 ; var_4 ++ ) { var_3 = Math . max ( var_3 , var_1 [ var_4 ] + var_2 [ var_4 + 1 ] ) ; } return var_3 ; }
3
2<SEP>0<SEP>1
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_0 ( List < Integer > var_1 , List < List < Integer >> var_2 ) { Map < Integer , List < Integer >> var_3 = new HashMap < > ( ) ; for ( int var_4 : var_1 ) { for ( int var_5 : var_2 . get ( var_4 ) ) { var_3 . putIfAbsent ( var_5 , new ArrayList < > ( ) ) ; var_3 . get ( var_5 ) . add ( var_4 ) ; } } return var_3 ; }
0
null
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_1 = var_0 . length , var_2 = var_0 [ 0 ] . length ; int [ ] [ ] var_3 = new int [ var_1 + 1 ] [ var_2 ] ; for ( int var_4 = 1 ; var_4 <= var_1 ; var_4 ++ ) { for ( int var_5 = 0 ; var_5 < var_2 ; var_5 ++ ) { var_3 [ var_4 ] [ var_5 ] = Integer . MAX_VALUE ; for ( int var_6 = 0 ; var_6 < var_2 ; var_6 ++ ) { if ( var_5 == var_6 ) continue ; var_3 [ var_4 ] [ var_5 ] = Math . min ( var_3 [ var_4 ] [ var_5 ] , var_3 [ var_4 - 1 ] [ var_6 ] + var_0 [ var_4 - 1 ] [ var_5 ] ) ; } } } int min = Integer . MAX_VALUE ; for ( int var_5 = 0 ; var_5 < var_2 ; var_5 ++ ) min = Math . min ( min , var_3 [ var_1 ] [ var_5 ] ) ; return min ; }
2
0<SEP>1
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_0 ( int [ ] var_1 , int var_2 ) { ArrayList < ArrayList < Integer >> var_3 = new ArrayList < ArrayList < Integer >> ( ) ; if ( var_1 == null || var_1 . length < 4 ) { return var_3 ; } Arrays . sort ( var_1 ) ; for ( int var_4 = 0 ; var_4 < var_1 . length - 3 ; var_4 ++ ) { if ( var_4 != 0 && var_1 [ var_4 ] == var_1 [ var_4 - 1 ] ) { continue ; } for ( int var_5 = var_4 + 1 ; var_5 < var_1 . length - 2 ; var_5 ++ ) { if ( var_5 != var_4 + 1 && var_1 [ var_5 ] == var_1 [ var_5 - 1 ] ) { continue ; } int var_6 = var_5 + 1 ; int var_7 = var_1 . length - 1 ; while ( var_6 < var_7 ) { int var_8 = var_1 [ var_4 ] + var_1 [ var_5 ] + var_1 [ var_6 ] + var_1 [ var_7 ] ; if ( var_8 < var_2 ) { var_6 ++ ; } else if ( var_8 > var_2 ) { var_7 -- ; } else { ArrayList < Integer > var_9 = new ArrayList < Integer > ( ) ; var_9 . add ( var_1 [ var_4 ] ) ; var_9 . add ( var_1 [ var_5 ] ) ; var_9 . add ( var_1 [ var_6 ] ) ; var_9 . add ( var_1 [ var_7 ] ) ; var_3 . add ( var_9 ) ; var_6 ++ ; var_7 -- ; while ( var_6 < var_7 && var_1 [ var_6 ] == var_1 [ var_6 - 1 ] ) { var_6 ++ ; } while ( var_6 < var_7 && var_1 [ var_7 ] == var_1 [ var_7 + 1 ] ) { var_7 -- ; } } } } } return var_3 ; }
5
4<SEP>2<SEP>0<SEP>1<SEP>3
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_2 = new StringBuffer ( ) ; for ( int var_3 = 0 ; var_3 < var_1 ; var_3 ++ ) var_2 . append ( " " ) ; return var_2 . toString ( ) ; }
3
0<SEP><D_QUOTE> <D_QUOTE><SEP><D_QUOTE><D_QUOTE>
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_0 , int var_1 , int var_2 ) { if ( var_0 == null || var_0 . length == 0 || ( var_1 == 0 && var_2 == 0 ) ) { return 0 ; } int var_3 = var_0 . length ; int [ ] [ ] [ ] var_4 = new int [ var_1 + 1 ] [ var_2 + 1 ] [ 2 ] ; int var_5 = 1 ; int var_6 = 0 ; int [ ] var_7 = new int [ var_3 ] ; int [ ] var_8 = new int [ var_3 ] ; for ( int var_9 = 0 ; var_9 < var_3 ; var_9 ++ ) { char [ ] var_10 = var_0 [ var_9 ] . toCharArray ( ) ; for ( char var_11 : var_10 ) { var_7 [ var_9 ] += var_11 == '1' ? 1 : 0 ; var_8 [ var_9 ] += var_11 == '0' ? 1 : 0 ; } } for ( int var_9 = 0 ; var_9 <= var_3 ; var_9 ++ ) { var_6 = var_5 ; var_5 = 1 - var_6 ; for ( int var_12 = 0 ; var_12 <= var_1 ; var_12 ++ ) { for ( int var_13 = 0 ; var_13 <= var_2 ; var_13 ++ ) { if ( var_9 == 0 || ( var_12 == 0 && var_13 == 0 ) ) { var_4 [ var_12 ] [ var_13 ] [ var_5 ] = 0 ; continue ; } var_4 [ var_12 ] [ var_13 ] [ var_5 ] = var_4 [ var_12 ] [ var_13 ] [ var_6 ] ; int var_14 = var_8 [ var_9 - 1 ] ; int var_15 = var_7 [ var_9 - 1 ] ; if ( var_12 >= var_14 && var_13 >= var_15 ) { var_4 [ var_12 ] [ var_13 ] [ var_5 ] = Math . max ( var_4 [ var_12 ] [ var_13 ] [ var_5 ] , var_4 [ var_12 - var_14 ] [ var_13 - var_15 ] [ var_6 ] + 1 ) ; } } } } return var_4 [ var_1 ] [ var_2 ] [ var_5 ] ; }
5
2<SEP>0<SEP>1<SEP><S_QUOTE>0<S_QUOTE><SEP><S_QUOTE>1<S_QUOTE>
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_2 = 0 ; for ( int var_3 = 1 ; var_3 < var_1 . length ; var_3 ++ ) { if ( var_1 [ var_3 ] > var_1 [ var_3 - 1 ] ) { var_2 += var_1 [ var_3 ] - var_1 [ var_3 - 1 ] ; } } return var_2 ; } int [ ] [ ] var_4 = new int [ var_1 . length ] [ var_0 + 1 ] ; int [ ] [ ] var_5 = new int [ var_1 . length ] [ var_0 + 1 ] ; for ( int var_3 = 1 ; var_3 < var_1 . length ; var_3 ++ ) { int var_6 = var_1 [ var_3 ] - var_1 [ var_3 - 1 ] ; for ( int var_7 = 1 ; var_7 <= var_0 ; var_7 ++ ) { var_4 [ var_3 ] [ var_7 ] = Math . max ( var_5 [ var_3 - 1 ] [ var_7 - 1 ] + var_6 , var_4 [ var_3 - 1 ] [ var_7 ] + var_6 ) ; var_5 [ var_3 ] [ var_7 ] = Math . max ( var_5 [ var_3 - 1 ] [ var_7 ] , var_4 [ var_3 ] [ var_7 ] ) ; } } return var_5 [ var_1 . length - 1 ] [ var_0 ] ; }
3
0<SEP>1<SEP>2
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_0 ) { int [ ] var_1 = new int [ 256 ] ; for ( char var_2 : var_0 . toCharArray ( ) ) var_1 [ var_2 - 'a' ] ++ ; for ( int var_3 = 0 ; var_3 < var_0 . length ( ) ; var_3 ++ ) { if ( var_1 [ var_0 . charAt ( var_3 ) - 'a' ] == 1 ) return var_3 ; } return - 1 ; }
4
0<SEP>1<SEP>256<SEP><S_QUOTE>a<S_QUOTE>
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_0 ( int [ ] var_1 ) { List < List < Integer >> var_2 = new ArrayList < > ( ) ; if ( var_1 == null || var_1 . length == 0 ) { return var_2 ; } int var_3 = var_1 . length ; long var_4 = ( long ) Math . pow ( 2 , var_3 ) - 1 ; for ( int var_5 = 0 ; var_5 <= var_4 ; var_5 ++ ) { List < Integer > var_6 = new ArrayList < > ( ) ; int var_7 = 0 ; int var_8 = var_5 ; while ( var_8 != 0 ) { if ( ( var_8 & 1 ) == 1 ) { var_6 . add ( var_1 [ var_7 ] ) ; } var_8 = var_8 >> 1 ; var_7 ++ ; } var_2 . add ( var_6 ) ; } return var_2 ; }
3
0<SEP>1<SEP>2
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_0 ( ArrayList < String > var_1 ) { int var_2 = Integer . MIN_VALUE ; ArrayList < String > var_3 = new ArrayList < > ( ) ; for ( int var_4 = var_1 . size ( ) - 1 ; var_4 >= 0 ; var_4 -- ) { String var_5 = var_1 . get ( var_4 ) ; while ( var_5 . length ( ) != 0 ) { if ( var_1 . contains ( var_5 ) ) { if ( var_5 . length ( ) == 1 ) { if ( var_1 . get ( var_4 ) . length ( ) < var_2 ) { return var_3 ; } else { var_3 . add ( var_1 . get ( var_4 ) ) ; var_2 = var_1 . get ( var_4 ) . length ( ) ; } } var_5 = var_5 . substring ( 0 , var_5 . length ( ) - 1 ) ; } else { break ; } } } return var_3 ; }
2
1<SEP>0
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_3 = 0 ; for ( int var_4 = 0 ; var_4 < var_0 . length ; var_4 ++ ) { var_3 += var_0 [ var_4 ] ; if ( var_3 == var_1 ) { var_3 = 0 ; var_2 -- ; } else if ( var_3 < var_1 ) { if ( var_4 + 1 >= var_0 . length || var_3 + var_0 [ var_4 + 1 ] > var_1 ) { var_3 = 0 ; var_2 -- ; } } else { return - 1 ; } } return var_2 ; }
2
0<SEP>1
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_1 = var_0 . length ; int [ ] [ ] var_2 = new int [ var_1 ] [ 2 ] ; var_2 [ 0 ] [ 0 ] = 0 ; var_2 [ 1 ] [ 0 ] = var_0 [ 1 ] ; var_2 [ 0 ] [ 1 ] = var_0 [ 0 ] ; var_2 [ 1 ] [ 1 ] = var_2 [ 0 ] [ 1 ] ; for ( int var_3 = 2 ; var_3 < var_1 ; var_3 ++ ) { if ( var_3 == var_1 - 1 ) { var_2 [ var_3 ] [ 0 ] = Math . max ( var_2 [ var_3 - 1 ] [ 0 ] , var_2 [ var_3 - 2 ] [ 0 ] + var_0 [ var_3 ] ) ; var_2 [ var_3 ] [ 1 ] = var_2 [ var_3 - 1 ] [ 1 ] ; } else { var_2 [ var_3 ] [ 0 ] = Math . max ( var_2 [ var_3 - 1 ] [ 0 ] , var_2 [ var_3 - 2 ] [ 0 ] + var_0 [ var_3 ] ) ; var_2 [ var_3 ] [ 1 ] = Math . max ( var_2 [ var_3 - 1 ] [ 1 ] , var_2 [ var_3 - 2 ] [ 1 ] + var_0 [ var_3 ] ) ; } } return Math . max ( var_2 [ var_1 - 1 ] [ 0 ] , var_2 [ var_1 - 1 ] [ 1 ] ) ; }
3
2<SEP>0<SEP>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_1 , String var_2 ) { if ( var_1 == null || var_2 == null || var_1 . length ( ) == 0 || var_2 . length ( ) == 0 ) { return "0A0B" ; } char [ ] var_3 = var_1 . toCharArray ( ) ; char [ ] var_4 = var_2 . toCharArray ( ) ; Map < Character , Integer > var_5 = new HashMap < > ( ) ; Map < Character , Integer > var_6 = new HashMap < > ( ) ; int var_7 = 0 ; for ( int var_8 = 0 ; var_8 < var_3 . length ; var_8 ++ ) { char var_9 = var_3 [ var_8 ] , var_10 = var_4 [ var_8 ] ; if ( var_9 == var_10 ) { var_7 ++ ; } else { var_5 . putIfAbsent ( var_9 , 0 ) ; var_5 . put ( var_9 , var_5 . get ( var_9 ) + 1 ) ; var_6 . putIfAbsent ( var_10 , 0 ) ; var_6 . put ( var_10 , var_6 . get ( var_10 ) + 1 ) ; } } int var_11 = 0 ; for ( Map . Entry < Character , Integer > var_12 : var_5 . entrySet ( ) ) { char var_13 = var_12 . getKey ( ) ; if ( var_6 . containsKey ( var_13 ) ) { var_11 += Math . min ( var_12 . getValue ( ) , var_6 . get ( var_13 ) ) ; } } return String . format ( "%sA%sB" , var_7 , var_11 ) ; }
4
<D_QUOTE>0A0B<D_QUOTE><SEP>0<SEP><D_QUOTE>%sA%sB<D_QUOTE><SEP>1
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_0 ( int var_1 , int [ ] [ ] var_2 ) { Map < Integer , Set < Integer >> var_3 = new HashMap < > ( ) ; for ( int var_4 = 0 ; var_4 < var_1 ; var_4 ++ ) var_3 . putIfAbsent ( var_4 , new HashSet < > ( ) ) ; for ( int [ ] var_5 : var_2 ) { var_3 . get ( var_5 [ 0 ] ) . add ( var_5 [ 1 ] ) ; var_3 . get ( var_5 [ 1 ] ) . add ( var_5 [ 0 ] ) ; } return var_3 ; }
2
0<SEP>1
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_0 ( int var_1 ) { List < List < Integer >> var_2 = new ArrayList < > ( ) ; if ( var_1 == 0 ) return var_2 ; if ( var_1 >= 1 ) var_2 . add ( Arrays . asList ( 1 ) ) ; if ( var_1 >= 2 ) var_2 . add ( Arrays . asList ( 1 , 1 ) ) ; for ( int var_3 = 2 ; var_3 < var_1 ; var_3 ++ ) { List < Integer > var_4 = new ArrayList < > ( Arrays . asList ( 1 , 1 ) ) ; List < Integer > var_5 = var_2 . get ( var_3 - 1 ) ; int var_6 = var_3 - 1 ; for ( int var_7 = 1 ; var_7 <= var_6 ; var_7 ++ ) { var_4 . add ( var_7 , var_5 . get ( var_7 ) + var_5 . get ( var_7 - 1 ) ) ; } var_2 . add ( var_4 ) ; } return var_2 ; }
3
2<SEP>0<SEP>1
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 ; }
3
2<SEP>0<SEP>1
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 ; }
2
1<SEP>0
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_0 , int var_1 ) { if ( var_0 == null || var_0 . length ( ) == 0 ) return 0 ; int var_2 = var_0 . length ( ) ; Map < Character , Integer > var_3 = new LinkedHashMap < > ( var_1 + 1 ) ; int var_4 = 0 , var_5 = 0 , max = 0 ; while ( var_5 < var_2 ) { char var_6 = var_0 . charAt ( var_5 ) ; if ( var_3 . containsKey ( var_6 ) ) var_3 . remove ( var_6 ) ; var_3 . put ( var_6 , var_5 ++ ) ; if ( var_3 . size ( ) > var_1 ) { Map . Entry < Character , Integer > var_7 = var_3 . entrySet ( ) . iterator ( ) . next ( ) ; var_3 . remove ( var_7 . getKey ( ) ) ; var_4 = var_7 . getValue ( ) + 1 ; } max = Math . max ( max , var_5 - var_4 ) ; } return max ; }
2
0<SEP>1
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_1 , int var_2 , boolean var_3 ) { var_1 [ var_2 ] = var_3 ; var_1 [ var_2 + 1 ] = var_3 ; }
1
1
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_1 = - 1 ; for ( int var_2 = 0 ; var_2 < var_0 . length ; var_2 ++ ) { if ( var_0 [ var_2 ] > 0 ) { if ( var_1 < 0 ) { var_1 = var_0 [ var_2 ] ; if ( var_1 != 1 ) { return 1 ; } } else if ( var_0 [ var_2 ] == var_0 [ var_2 - 1 ] ) { var_1 -- ; } else if ( var_0 [ var_2 ] != var_1 ) { return var_1 ; } var_1 ++ ; } } if ( var_1 < 0 ) { return 1 ; } return var_1 ; }
2
0<SEP>1
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_2 = new boolean [ 3 ] ; var_2 [ 0 ] = var_2 [ 1 ] = var_2 [ 2 ] = true ; for ( int var_3 = 3 ; var_3 < var_1 ; var_3 ++ ) { var_2 [ var_3 % 3 ] = ! var_2 [ ( var_3 - 1 ) % 3 ] || ! var_2 [ ( var_3 - 2 ) % 3 ] || ! var_2 [ ( var_3 - 3 ) % 3 ] ; } return var_2 [ ( var_1 - 1 ) % 3 ] ; }
4
2<SEP>0<SEP>3<SEP>1
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_1 = 0 ; Arrays . sort ( var_0 ) ; for ( int var_2 = 2 ; var_2 < var_0 . length ; var_2 ++ ) { int var_3 = 0 ; int var_4 = var_2 - 1 ; while ( var_3 < var_4 ) { if ( var_0 [ var_3 ] + var_0 [ var_4 ] > var_0 [ var_2 ] ) { var_1 += var_4 - var_3 ; var_4 -- ; } else { var_3 ++ ; } } } return var_1 ; }
3
0<SEP>1<SEP>2
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_1 = var_0 . length ; int [ ] var_2 = new int [ 2 ] ; var_2 [ 0 ] = 1 ; int max = 1 ; for ( int var_3 = 1 ; var_3 < var_1 ; var_3 ++ ) { var_2 [ var_3 % 2 ] = 1 ; if ( var_0 [ var_3 ] > var_0 [ var_3 - 1 ] ) var_2 [ var_3 % 2 ] = Math . max ( var_2 [ var_3 % 2 ] , var_2 [ ( var_3 - 1 ) % 2 ] + 1 ) ; max = Math . max ( max , var_2 [ var_3 % 2 ] ) ; } return max ; }
3
0<SEP>1<SEP>2
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_1 = var_0 . length , var_2 = 0 , var_3 = var_1 - 1 ; int var_4 = var_0 [ 0 ] , var_5 = var_0 [ var_1 - 1 ] ; int var_6 = 0 ; while ( var_2 < var_3 ) { if ( var_4 < var_5 ) { var_2 ++ ; if ( var_4 > var_0 [ var_2 ] ) var_6 += var_4 - var_0 [ var_2 ] ; else var_4 = var_0 [ var_2 ] ; } else { var_3 -- ; if ( var_5 > var_0 [ var_3 ] ) var_6 += var_5 - var_0 [ var_3 ] ; else var_5 = var_0 [ var_3 ] ; } } return var_6 ; }
2
0<SEP>1
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_1 = var_0 . length , var_2 = 0 , var_3 = 0 ; int [ ] var_4 = new int [ var_1 ] ; int [ ] var_5 = new int [ var_1 ] ; for ( int var_6 = 0 ; var_6 < var_1 ; var_6 ++ ) { var_4 [ var_6 ] = 1 ; var_5 [ var_6 ] = 1 ; for ( int var_7 = 0 ; var_7 < var_6 ; var_7 ++ ) { if ( var_0 [ var_7 ] < var_0 [ var_6 ] ) { if ( var_4 [ var_6 ] == var_4 [ var_7 ] + 1 ) { var_5 [ var_6 ] += var_5 [ var_7 ] ; } else if ( var_4 [ var_6 ] < var_4 [ var_7 ] + 1 ) { var_4 [ var_6 ] = var_4 [ var_7 ] + 1 ; var_5 [ var_6 ] = var_5 [ var_7 ] ; } } } if ( var_2 == var_4 [ var_6 ] ) { var_3 += var_5 [ var_6 ] ; } else if ( var_2 < var_4 [ var_6 ] ) { var_2 = var_4 [ var_6 ] ; var_3 = var_5 [ var_6 ] ; } } return var_3 ; }
2
0<SEP>1
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_2 = var_0 . length ; int [ ] [ ] var_3 = new int [ var_2 + 1 ] [ 2 ] ; var_3 [ 0 ] [ 0 ] = var_3 [ 0 ] [ 1 ] = 0 ; var_3 [ 1 ] [ 1 ] = 0 ; var_3 [ 1 ] [ 0 ] = - var_0 [ 0 ] ; for ( int var_4 = 2 ; var_4 <= var_2 ; var_4 ++ ) { var_3 [ var_4 ] [ 0 ] = Math . max ( var_3 [ var_4 - 1 ] [ 0 ] , var_3 [ var_4 - 1 ] [ 1 ] - var_0 [ var_4 - 1 ] ) ; var_3 [ var_4 ] [ 1 ] = Math . max ( var_3 [ var_4 - 1 ] [ 1 ] , var_3 [ var_4 - 1 ] [ 0 ] + var_0 [ var_4 - 1 ] - var_1 ) ; } return var_3 [ var_2 ] [ 1 ] ; }
3
1<SEP>0<SEP>2
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_0 ( int [ ] var_1 , int [ ] var_2 , int [ ] var_3 ) { List < Integer > var_4 = new LinkedList < > ( ) ; int var_5 = var_1 . length - 1 , var_6 = var_2 . length - 1 , var_7 = var_3 . length - 1 ; while ( var_5 >= 0 && var_6 >= 0 && var_7 >= 0 ) { if ( var_1 [ var_5 ] == var_2 [ var_6 ] && var_2 [ var_6 ] == var_3 [ var_7 ] ) { if ( var_4 . isEmpty ( ) || var_1 [ var_5 ] != var_4 . get ( var_4 . size ( ) - 1 ) ) var_4 . add ( 0 , var_1 [ var_5 ] ) ; var_5 -- ; var_6 -- ; var_7 -- ; } else if ( var_2 [ var_6 ] < var_3 [ var_7 ] ) var_7 -- ; else if ( var_1 [ var_5 ] < var_2 [ var_6 ] ) var_6 -- ; else var_5 -- ; } return var_4 ; }
2
1<SEP>0
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_2 = 0 ; for ( int var_3 = 0 ; var_3 < 32 ; var_3 ++ ) { var_2 += ( var_0 ^ var_1 ) >> var_3 & 1 ; } return var_2 ; }
3
0<SEP>32<SEP>1
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_1 = 0 ; for ( int var_2 = 1 ; var_2 <= 32 ; var_2 ++ ) { var_1 += var_0 >> var_2 & 1 ; } return var_1 ; }
3
0<SEP>32<SEP>1
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 ; }
2
0<SEP>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' ) ; }
1
<S_QUOTE>0<S_QUOTE>
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_1 = 0 ; for ( int var_2 : var_0 ) { var_1 = var_1 ^ var_2 ; } return var_1 ; }
1
0
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 ) ; } }
2
1<SEP>0
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 ; }
2
0<SEP>1
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_0 , String var_1 ) { if ( var_0 == null || var_1 == null || var_0 . length ( ) == 0 || var_1 . length ( ) == 0 ) { return 0 ; } int var_2 = var_0 . length ( ) ; int var_3 = var_1 . length ( ) ; int [ ] [ ] var_4 = new int [ var_2 + 1 ] [ var_3 + 1 ] ; for ( int var_5 = 0 ; var_5 <= var_2 ; var_5 ++ ) { for ( int var_6 = 0 ; var_6 <= var_3 ; var_6 ++ ) { if ( var_5 == 0 || var_6 == 0 ) { var_4 [ var_5 ] [ var_6 ] = 0 ; continue ; } var_4 [ var_5 ] [ var_6 ] = Math . max ( var_4 [ var_5 - 1 ] [ var_6 ] , var_4 [ var_5 ] [ var_6 - 1 ] ) ; if ( var_0 . charAt ( var_5 - 1 ) == var_1 . charAt ( var_6 - 1 ) ) { var_4 [ var_5 ] [ var_6 ] = Math . max ( var_4 [ var_5 ] [ var_6 ] , var_4 [ var_5 - 1 ] [ var_6 - 1 ] + 1 ) ; } } } return var_4 [ var_2 ] [ var_3 ] ; }
2
0<SEP>1
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 ] ; }
1
0
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_0 ) { if ( var_0 == null || var_0 . length ( ) == 0 ) { return 0 ; } int var_1 = 0 , var_2 = 0 ; for ( char var_3 : var_0 . toCharArray ( ) ) { if ( var_3 == '(' ) var_2 ++ ; else if ( var_2 == 0 ) var_1 ++ ; else var_2 -- ; } return var_1 + var_2 ; }
2
0<SEP><S_QUOTE>(<S_QUOTE>
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 ; }
1
<D_QUOTE>@<D_QUOTE>
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_1 , int var_2 ) { if ( var_1 . peekFirst ( ) == var_2 ) var_1 . pollFirst ( ) ; }
0
null
300
<awangdev>[lint]. Anagrams_1.java
public List<String> anagrams(String[] strs) { List<String> rst = new ArrayList<>(); if (strs == null || strs == null) return rst; Map<String, List<String>> map = new HashMap<>(); for (String word : strs){ int[] arr = new int[26]; for (char c : word.toCharArray()) arr[c - 'a']++; String key = Arrays.toString(arr); map.putIfAbsent(key, new ArrayList<>()); map.get(key).add(word); } for (List<String> list : map.values()) { if (list.size() >= 2) rst.addAll(list); } return rst; }
public List < String > var_0 ( String [ ] var_1 ) { List < String > var_2 = new ArrayList < > ( ) ; if ( var_1 == null || var_1 == null ) return var_2 ; Map < String , List < String >> var_3 = new HashMap < > ( ) ; for ( String var_4 : var_1 ) { int [ ] var_5 = new int [ 26 ] ; for ( char var_6 : var_4 . toCharArray ( ) ) var_5 [ var_6 - 'a' ] ++ ; String var_7 = Arrays . toString ( var_5 ) ; var_3 . putIfAbsent ( var_7 , new ArrayList < > ( ) ) ; var_3 . get ( var_7 ) . add ( var_4 ) ; } for ( List < String > var_8 : var_3 . values ( ) ) { if ( var_8 . size ( ) >= 2 ) var_2 . addAll ( var_8 ) ; } return var_2 ; }
3
2<SEP>26<SEP><S_QUOTE>a<S_QUOTE>
301
<awangdev>Find Minimum in Rotated Sorted Array_1.java
public int findMin(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 (mid - 1 >= 0 && mid + 1 < n && nums[mid - 1] > nums[mid] && nums[mid] < nums[mid + 1]) { return nums[mid]; } else if (nums[mid] > nums[end]) { start = mid; } else { end = mid; } } return nums[start] < nums[end] ? nums[start] : nums[end]; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_1 = var_0 . length ; int var_2 = 0 ; int var_3 = var_1 - 1 ; while ( var_2 + 1 < var_3 ) { int var_4 = ( var_2 + var_3 ) >> 1 ; if ( var_4 - 1 >= 0 && var_4 + 1 < var_1 && var_0 [ var_4 - 1 ] > var_0 [ var_4 ] && var_0 [ var_4 ] < var_0 [ var_4 + 1 ] ) { return var_0 [ var_4 ] ; } else if ( var_0 [ var_4 ] > var_0 [ var_3 ] ) { var_2 = var_4 ; } else { var_3 = var_4 ; } } return var_0 [ var_2 ] < var_0 [ var_3 ] ? var_0 [ var_2 ] : var_0 [ var_3 ] ; }
2
0<SEP>1
302
<awangdev>Orderly Queue_1.java
public String orderlyQueue(String S, int K) { if (K > 1) { char[] arr = S.toCharArray(); Arrays.sort(arr); return new String(arr); } String res = S; for (int i = 1; i < S.length(); i++) { String tmp = S.substring(i) + S.substring(0, i); if (res.compareTo(tmp) > 0) res = tmp; } return res; }
public String var_0 ( String var_1 , int var_2 ) { if ( var_2 > 1 ) { char [ ] var_3 = var_1 . toCharArray ( ) ; Arrays . sort ( var_3 ) ; return new String ( var_3 ) ; } String var_4 = var_1 ; for ( int var_5 = 1 ; var_5 < var_1 . length ( ) ; var_5 ++ ) { String var_6 = var_1 . substring ( var_5 ) + var_1 . substring ( 0 , var_5 ) ; if ( var_4 . compareTo ( var_6 ) > 0 ) var_4 = var_6 ; } return var_4 ; }
2
1<SEP>0
303
<awangdev>274.H-Index_2.java
public int hIndex(int[] citations) { if (citations == null || citations.length == 0) { return 0; } int n = citations.length; Arrays.sort(citations); int i = 0; while (i < n && citations[i] < n - i) { i++; } return n - i; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_1 = var_0 . length ; Arrays . sort ( var_0 ) ; int var_2 = 0 ; while ( var_2 < var_1 && var_0 [ var_2 ] < var_1 - var_2 ) { var_2 ++ ; } return var_1 - var_2 ; }
1
0
304
<awangdev>Walls and Gates_2.java
private boolean validate(int[][] rooms) { return rooms == null || rooms.length == 0 || rooms[0] == null || rooms[0].length == 0; }
private boolean var_0 ( int [ ] [ ] var_1 ) { return var_1 == null || var_1 . length == 0 || var_1 [ 0 ] == null || var_1 [ 0 ] . length == 0 ; }
1
0
305
<awangdev>Word Ladder_3.java
public int compare(String s1, String s2) { int count = 0; for (int i = 0; i < s1.length(); i++) { count += s1.charAt(i) != s2.charAt(i) ? 1 : 0; if (count > 1) { return count; } } return count; }
public int sample_funcname ( String var_0 , String var_1 ) { int var_2 = 0 ; for ( int var_3 = 0 ; var_3 < var_0 . length ( ) ; var_3 ++ ) { var_2 += var_0 . charAt ( var_3 ) != var_1 . charAt ( var_3 ) ? 1 : 0 ; if ( var_2 > 1 ) { return var_2 ; } } return var_2 ; }
2
0<SEP>1
306
<awangdev>Ugly Number II_1.java
public int nthUglyNumber(int n) { if (n <= 1) return n; int[] dp = new int[n]; dp[0] = 1; int index2 = 0, index3 = 0, index5 = 0; int factor2 = 2, factor3 = 3, factor5 = 5; for (int i = 1; i < n; i++){ int min = Math.min(Math.min(factor2, factor3), factor5); dp[i] = min; if (factor2 == min) factor2 = dp[++index2] * 2; if (factor3 == min) factor3 = dp[++index3] * 3; if (factor5 == min) factor5 = dp[++index5] * 5; } return dp[n-1]; }
public int sample_funcname ( int var_0 ) { if ( var_0 <= 1 ) return var_0 ; int [ ] var_1 = new int [ var_0 ] ; var_1 [ 0 ] = 1 ; int var_2 = 0 , var_3 = 0 , var_4 = 0 ; int var_5 = 2 , var_6 = 3 , var_7 = 5 ; for ( int var_8 = 1 ; var_8 < var_0 ; var_8 ++ ) { int min = Math . min ( Math . min ( var_5 , var_6 ) , var_7 ) ; var_1 [ var_8 ] = min ; if ( var_5 == min ) var_5 = var_1 [ ++ var_2 ] * 2 ; if ( var_6 == min ) var_6 = var_1 [ ++ var_3 ] * 3 ; if ( var_7 == min ) var_7 = var_1 [ ++ var_4 ] * 5 ; } return var_1 [ var_0 - 1 ] ; }
5
2<SEP>1<SEP>3<SEP>0<SEP>5
307
<awangdev>Search for a Range_2.java
public ArrayList<Integer> searchRange(ArrayList<Integer> A, int target) { int start = 0; int end = A.size() - 1; int mid; ArrayList<Integer> bound = new ArrayList<Integer>(); bound.add(-1); bound.add(-1); if ( A.size() == 0) { return bound; } while (start + 1 < end) { mid = start + (end - start) / 2; if (A.get(mid) < target) { start = mid; } else if (A.get(mid) > target) { end = mid; } else { end = mid; } } if (A.get(start) == target) { bound.set(0, start); } else if (A.get(end) == target) { bound.set(0, end); } else { return bound; } start = 0; end = A.size() - 1; while (start + 1 < end) { mid = start + (end - start) / 2; if (A.get(mid) < target) { start = mid; } else if (A.get(mid) > target) { end = mid; } else { start = mid; } } if (A.get(end) == target) { bound.set(1, end); } else if (A.get(start) == target) { bound.set(1, start); } else { return bound; } return bound; }
public ArrayList < Integer > var_0 ( ArrayList < Integer > var_1 , int var_2 ) { int var_3 = 0 ; int var_4 = var_1 . size ( ) - 1 ; int var_5 ; ArrayList < Integer > var_6 = new ArrayList < Integer > ( ) ; var_6 . add ( - 1 ) ; var_6 . add ( - 1 ) ; if ( var_1 . size ( ) == 0 ) { return var_6 ; } while ( var_3 + 1 < var_4 ) { var_5 = var_3 + ( var_4 - var_3 ) / 2 ; if ( var_1 . get ( var_5 ) < var_2 ) { var_3 = var_5 ; } else if ( var_1 . get ( var_5 ) > var_2 ) { var_4 = var_5 ; } else { var_4 = var_5 ; } } if ( var_1 . get ( var_3 ) == var_2 ) { var_6 . set ( 0 , var_3 ) ; } else if ( var_1 . get ( var_4 ) == var_2 ) { var_6 . set ( 0 , var_4 ) ; } else { return var_6 ; } var_3 = 0 ; var_4 = var_1 . size ( ) - 1 ; while ( var_3 + 1 < var_4 ) { var_5 = var_3 + ( var_4 - var_3 ) / 2 ; if ( var_1 . get ( var_5 ) < var_2 ) { var_3 = var_5 ; } else if ( var_1 . get ( var_5 ) > var_2 ) { var_4 = var_5 ; } else { var_3 = var_5 ; } } if ( var_1 . get ( var_4 ) == var_2 ) { var_6 . set ( 1 , var_4 ) ; } else if ( var_1 . get ( var_3 ) == var_2 ) { var_6 . set ( 1 , var_3 ) ; } else { return var_6 ; } return var_6 ; }
3
2<SEP>0<SEP>1
308
<awangdev>Backpack III_3.java
public int backPackIII(int[] A, int[] V, int m) { if (A == null || A.length == 0 || V == null || V.length == 0 || m <= 0) { return 0; } int n = A.length; int[] dp = new int[m + 1]; dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = A[i - 1]; j <= m && j >= A[i - 1]; j++) { dp[j] = Math.max(dp[j], dp[j - A[i - 1]] + V[i - 1]); } } return dp[m]; }
public int sample_funcname ( int [ ] var_0 , int [ ] var_1 , int var_2 ) { if ( var_0 == null || var_0 . length == 0 || var_1 == null || var_1 . length == 0 || var_2 <= 0 ) { return 0 ; } int var_3 = var_0 . length ; int [ ] var_4 = new int [ var_2 + 1 ] ; var_4 [ 0 ] = 0 ; for ( int var_5 = 1 ; var_5 <= var_3 ; var_5 ++ ) { for ( int var_6 = var_0 [ var_5 - 1 ] ; var_6 <= var_2 && var_6 >= var_0 [ var_5 - 1 ] ; var_6 ++ ) { var_4 [ var_6 ] = Math . max ( var_4 [ var_6 ] , var_4 [ var_6 - var_0 [ var_5 - 1 ] ] + var_1 [ var_5 - 1 ] ) ; } } return var_4 [ var_2 ] ; }
2
0<SEP>1
309
<awangdev>448. Find All Numbers Disappeared in an Array_1.java
private void swap(int[] nums, int a, int b) { int temp = nums[a]; nums[a] = nums[b]; nums[b] = 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 ; }
0
null