id
int64
0
1.17k
comefrom
stringlengths
21
84
code
stringlengths
50
1.89k
masked
stringlengths
63
2.47k
400
<awangdev>Interleaving String_4.java
public boolean isInterleave(String s1, String s2, String s3) { if (s3 == null || (s1 == null && s2 == null) || s1.length() + s2.length() != s3.length()) { return false; } int i = 0; int j = 0; String base = ""; for (int k = 0; k < s1.length()*s2.length() - 1; k++) { if (i < s1.length() || j < s2.length()) { if (i < s1.length() && s3.indexOf(base + s1.charAt(i)) == 0) { base += s1.charAt(i); i++; } else if (j < s2.length() && s3.indexOf(base + s2.charAt(j)) == 0) { base += s2.charAt(j); j++; } else { return false; } } } return true; }
public boolean var_0 ( String var_2 , String var_3 , String var_4 ) { if ( var_4 == null || ( var_2 == null && var_3 == null ) || var_2 . length ( ) + var_3 . length ( ) != var_4 . length ( ) ) { return false ; } int var_8 = 0 ; int var_9 = 0 ; String var_11 = "" ; for ( int var_12 = 0 ; var_12 < var_2 . length ( ) * var_3 . length ( ) - 1 ; var_12 ++ ) { if ( var_8 < var_2 . length ( ) || var_9 < var_3 . length ( ) ) { if ( var_8 < var_2 . length ( ) && var_4 . indexOf ( var_11 + var_2 . charAt ( var_8 ) ) == 0 ) { var_11 += var_2 . charAt ( var_8 ) ; var_8 ++ ; } else if ( var_9 < var_3 . length ( ) && var_4 . indexOf ( var_11 + var_3 . charAt ( var_9 ) ) == 0 ) { var_11 += var_3 . charAt ( var_9 ) ; var_9 ++ ; } else { return false ; } } } return true ; }
401
<awangdev>76. Minimum Window Substring_3.java
private boolean valid(int[] source, int[] target) { for (int i = 0; i < 256; i++) { if (source[i] < target[i]) return false; } return true; }
private boolean var_0 ( int [ ] var_1 , int [ ] var_2 ) { for ( int var_4 = 0 ; var_4 < 256 ; var_4 ++ ) { if ( var_1 [ var_4 ] < var_2 [ var_4 ] ) return false ; } return true ; }
402
<awangdev>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 ; }
403
<awangdev>151. Reverse Words in a String_3.java
private String output(char[] arr) { StringBuffer sb = new StringBuffer(); int count = 0; for (char c : arr) { count += c == ' ' ? 1 : 0; if (count != 0 & c != ' ') count = 0; if (count <= 1) sb.append(c); } return sb.toString().trim(); }
private String var_0 ( char [ ] var_1 ) { StringBuffer var_3 = new StringBuffer ( ) ; int var_5 = 0 ; for ( char var_6 : var_1 ) { var_5 += var_6 == ' ' ? 1 : 0 ; if ( var_5 != 0 & var_6 != ' ' ) var_5 = 0 ; if ( var_5 <= 1 ) var_3 . append ( var_6 ) ; } return var_3 . toString ( ) . trim ( ) ; }
404
<awangdev>875. Koko Eating Bananas_1.java
private int calc(int[] piles, double k) { int count = 0; for (int i : piles) { count += Math.ceil(i / k); } return count; }
private int sample_funcname ( int [ ] var_0 , double var_1 ) { int var_3 = 0 ; for ( int var_4 : var_0 ) { var_3 += Math . ceil ( var_4 / var_1 ) ; } return var_3 ; }
405
<awangdev>Bricks Falling When Hit_3.java
private boolean validate(int[][] 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 ( int [ ] [ ] 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 ; }
406
<awangdev>Backpack III_4.java
public int backPackIII(int[] A, int[] V, int m) { if (A == null || V == null || A.length != V.length) { return 0; } int n = A.length; int[][] dp = new int[n + 1][m + 1]; for (int j = 0; j <= m; j++) { dp[0][j] = -1; } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { for (int k = 0; k * A[i - 1] <= m; k++) { if (j - k * A[i - 1] >= 0 && dp[i - 1][j - k * A[i - 1]] != -1) { dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - k * A[i - 1]] + k * V[i - 1]); } } } } int rst = 0; for (int j = 0; j <= m; j++) { rst = Math.max(rst, dp[n][j]); } return rst; }
public int sample_funcname ( int [ ] var_0 , int [ ] var_1 , int var_2 ) { if ( var_0 == null || var_1 == null || var_0 . length != var_1 . length ) { return 0 ; } int var_6 = var_0 . length ; int [ ] [ ] var_8 = new int [ var_6 + 1 ] [ var_2 + 1 ] ; for ( int var_9 = 0 ; var_9 <= var_2 ; var_9 ++ ) { var_8 [ 0 ] [ var_9 ] = - 1 ; } var_8 [ 0 ] [ 0 ] = 0 ; for ( int var_10 = 1 ; var_10 <= var_6 ; var_10 ++ ) { for ( int var_9 = 0 ; var_9 <= var_2 ; var_9 ++ ) { for ( int var_11 = 0 ; var_11 * var_0 [ var_10 - 1 ] <= var_2 ; var_11 ++ ) { if ( var_9 - var_11 * var_0 [ var_10 - 1 ] >= 0 && var_8 [ var_10 - 1 ] [ var_9 - var_11 * var_0 [ var_10 - 1 ] ] != - 1 ) { var_8 [ var_10 ] [ var_9 ] = Math . max ( var_8 [ var_10 ] [ var_9 ] , var_8 [ var_10 - 1 ] [ var_9 - var_11 * var_0 [ var_10 - 1 ] ] + var_11 * var_1 [ var_10 - 1 ] ) ; } } } } int var_14 = 0 ; for ( int var_9 = 0 ; var_9 <= var_2 ; var_9 ++ ) { var_14 = Math . max ( var_14 , var_8 [ var_6 ] [ var_9 ] ) ; } return var_14 ; }
407
<awangdev>K Edit Distance_1.java
private boolean validate(String word, String target, int k) { if (word.equals(target)) { return true; } if (Math.abs(word.length() - target.length()) > k) { return false; } int m = word.length(); int n = target.length(); int[][] dp = new int[2][n + 1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0) { dp[i % 2][j] = j; continue; } if (j == 0) { dp[i % 2][j] = i; continue; } dp[i % 2][j] = Math.min(dp[(i - 1) % 2][j - 1], Math.min(dp[i % 2][j - 1], dp[(i - 1) % 2][j])) + 1; if (word.charAt(i - 1) == target.charAt(j - 1)) { dp[i % 2][j] = Math.min(dp[i % 2][j], dp[(i - 1) % 2][j - 1]); } } } return dp[m % 2][n] <= k; }
private boolean var_0 ( String var_2 , String var_3 , int var_4 ) { if ( var_2 . equals ( var_3 ) ) { return true ; } if ( Math . abs ( var_2 . length ( ) - var_3 . length ( ) ) > var_4 ) { return false ; } int var_9 = var_2 . length ( ) ; int var_10 = var_3 . length ( ) ; int [ ] [ ] var_13 = new int [ 2 ] [ var_10 + 1 ] ; for ( int var_15 = 0 ; var_15 <= var_9 ; var_15 ++ ) { for ( int var_16 = 0 ; var_16 <= var_10 ; var_16 ++ ) { if ( var_15 == 0 ) { var_13 [ var_15 % 2 ] [ var_16 ] = var_16 ; continue ; } if ( var_16 == 0 ) { var_13 [ var_15 % 2 ] [ var_16 ] = var_15 ; continue ; } var_13 [ var_15 % 2 ] [ var_16 ] = Math . min ( var_13 [ ( var_15 - 1 ) % 2 ] [ var_16 - 1 ] , Math . min ( var_13 [ var_15 % 2 ] [ var_16 - 1 ] , var_13 [ ( var_15 - 1 ) % 2 ] [ var_16 ] ) ) + 1 ; if ( var_2 . charAt ( var_15 - 1 ) == var_3 . charAt ( var_16 - 1 ) ) { var_13 [ var_15 % 2 ] [ var_16 ] = Math . min ( var_13 [ var_15 % 2 ] [ var_16 ] , var_13 [ ( var_15 - 1 ) % 2 ] [ var_16 - 1 ] ) ; } } } return var_13 [ var_9 % 2 ] [ var_10 ] <= var_4 ; }
408
<awangdev>105. Construct Binary Tree from Preorder and Inorder Traversal_1.java
private Map<Integer, Integer> buildMap(int[] inorder) { Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < inorder.length; i++) map.put(inorder[i], i); return map; }
private Map < Integer , Integer > var_1 ( int [ ] var_2 ) { Map < Integer , Integer > var_5 = new HashMap < > ( ) ; for ( int var_7 = 0 ; var_7 < var_2 . length ; var_7 ++ ) var_5 . put ( var_2 [ var_7 ] , var_7 ) ; return var_5 ; }
409
<awangdev>Encode and Decode Strings_1.java
public String encode(List<String> strs) { if (strs.size() == 0) { return ""; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < strs.size(); i++) { sb.append(strs.get(i).length() + "#" + strs.get(i)); } return sb.toString(); }
public String var_0 ( List < String > var_3 ) { if ( var_3 . size ( ) == 0 ) { return "" ; } StringBuffer var_8 = new StringBuffer ( ) ; for ( int var_9 = 0 ; var_9 < var_3 . size ( ) ; var_9 ++ ) { var_8 . append ( var_3 . get ( var_9 ) . length ( ) + "#" + var_3 . get ( var_9 ) ) ; } return var_8 . toString ( ) ; }
410
<awangdev>Unique Binary Search Tree_2.java
public int numTrees(int n) { if (n <= 1) { return 1; } int[] count = new int[n + 1]; count[0] = 1; count[1] = 1; for (int i = 2; i < n + 1; i++) { for (int j = 0; j < i; j++) { count[i] += count[j] * count[i - j - 1]; } } return count[n]; }
public int sample_funcname ( int var_0 ) { if ( var_0 <= 1 ) { return 1 ; } int [ ] var_2 = new int [ var_0 + 1 ] ; var_2 [ 0 ] = 1 ; var_2 [ 1 ] = 1 ; for ( int var_5 = 2 ; var_5 < var_0 + 1 ; var_5 ++ ) { for ( int var_6 = 0 ; var_6 < var_5 ; var_6 ++ ) { var_2 [ var_5 ] += var_2 [ var_6 ] * var_2 [ var_5 - var_6 - 1 ] ; } } return var_2 [ var_0 ] ; }
411
<awangdev>[lint]. Unique Characters_1.java
public boolean isUnique(String str) { if (str == null || str.length() == 0) return true; char[] arr = str.toCharArray(); Arrays.sort(arr); for (int i = 1; i < arr.length; i++) { if (arr[i] == arr[i - 1]) return false; } return true; }
public boolean var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) return true ; char [ ] var_7 = var_2 . toCharArray ( ) ; Arrays . sort ( var_7 ) ; for ( int var_11 = 1 ; var_11 < var_7 . length ; var_11 ++ ) { if ( var_7 [ var_11 ] == var_7 [ var_11 - 1 ] ) return false ; } return true ; }
412
<awangdev>Walls and Gates_5.java
private boolean validateCoordinate(int[][] rooms, int x, int y) { return x < 0 || x >= rooms.length || y < 0 || y >= rooms[0].length || rooms[x][y] == -1 || rooms[x][y] == 0; }
private boolean var_0 ( int [ ] [ ] 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 || var_1 [ var_2 ] [ var_3 ] == 0 ; }
413
<awangdev>724. Find Pivot Index_1.java
public int pivotIndex(int[] nums) { if (nums == null || nums.length == 0) return -1; int n = nums.length; for (int i = 1; i < n; i++) nums[i] += nums[i - 1]; if (nums[n-1] - nums[0] == 0) return 0; for (int i = 1; i < n; i++) { if (nums[i - 1] == nums[n - 1] - nums[i]) return i; } return -1; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return - 1 ; int var_5 = var_0 . length ; for ( int var_6 = 1 ; var_6 < var_5 ; var_6 ++ ) var_0 [ var_6 ] += var_0 [ var_6 - 1 ] ; if ( var_0 [ var_5 - 1 ] - var_0 [ 0 ] == 0 ) return 0 ; for ( int var_6 = 1 ; var_6 < var_5 ; var_6 ++ ) { if ( var_0 [ var_6 - 1 ] == var_0 [ var_5 - 1 ] - var_0 [ var_6 ] ) return var_6 ; } return - 1 ; }
414
<awangdev>Basic Calculator_1.java
private int getWeight(int base, char c) { if (c == '(') return base + 10; if (c == ')') return base - 10; if (c == '+' || c == '-') return base + 1; if (c == '*' || c == '/') return base + 2; return Integer.MAX_VALUE; }
private int sample_funcname ( int var_0 , char var_1 ) { if ( var_1 == '(' ) return var_0 + 10 ; if ( var_1 == ')' ) return var_0 - 10 ; if ( var_1 == '+' || var_1 == '-' ) return var_0 + 1 ; if ( var_1 == '*' || var_1 == '/' ) return var_0 + 2 ; return Integer . MAX_VALUE ; }
415
<awangdev>727. Minimum Window Subsequence_1.java
private int backtrack(char[] ss, char[] tt, int index) { for (int i = tt.length - 1; i >= 0; i--) { while(ss[index--] != tt[i]); } return index + 1; }
private int sample_funcname ( char [ ] var_0 , char [ ] var_1 , int var_2 ) { for ( int var_5 = var_1 . length - 1 ; var_5 >= 0 ; var_5 -- ) { while ( var_0 [ var_2 -- ] != var_1 [ var_5 ] ) ; } return var_2 + 1 ; }
416
<awangdev>139. Word Break_2.java
private boolean dfs(Set<String> dict, Set<String> set, String s) { if (dict.contains(s)) return true; StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); sb.append(c); if (dict.contains(sb.toString())) { String sub = s.substring(i + 1); if (set.contains(sub)) continue; if (dfs(dict, set, sub)) return true; set.add(sub); } } return false; }
private boolean sample_funcname ( Set < String > dict , Set < String > set , String s ) { if ( dict . contains ( s ) ) return true ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; sb . append ( c ) ; if ( dict . contains ( sb . toString ( ) ) ) { String sub = s . substring ( i + 1 ) ; if ( set . contains ( sub ) ) continue ; if ( dfs ( dict , set , sub ) ) return true ; set . add ( sub ) ; } } return false ; }
417
<awangdev>57. Insert Interval_3.java
private int[][] convert(List<int[]> list) { int[][] rst = new int[list.size()][2]; for (int i = 0; i < list.size(); i++) { rst[i][0] = list.get(i)[0]; rst[i][1] = list.get(i)[1]; } return rst; }
private int [ ] [ ] sample_funcname ( List < int [ ] > var_1 ) { int [ ] [ ] var_4 = new int [ var_1 . size ( ) ] [ 2 ] ; for ( int var_6 = 0 ; var_6 < var_1 . size ( ) ; var_6 ++ ) { var_4 [ var_6 ] [ 0 ] = var_1 . get ( var_6 ) [ 0 ] ; var_4 [ var_6 ] [ 1 ] = var_1 . get ( var_6 ) [ 1 ] ; } return var_4 ; }
418
<awangdev>Add Digits_1.java
public int addDigits(int num) { if (num < 10) { return num; } while (num > 9) { int temp = 0; while (num != 0) { temp += num % 10; num = num / 10; } num = temp; } return num; }
public int sample_funcname ( int var_0 ) { if ( var_0 < 10 ) { return var_0 ; } while ( var_0 > 9 ) { int var_4 = 0 ; while ( var_0 != 0 ) { var_4 += var_0 % 10 ; var_0 = var_0 / 10 ; } var_0 = var_4 ; } return var_0 ; }
419
<awangdev>896. Monotonic Array_1.java
private boolean validate(int a, int b, boolean incline) { if (incline) return a <= b; return a >= b; }
private boolean var_0 ( int var_1 , int var_2 , boolean var_4 ) { if ( var_4 ) return var_1 <= var_2 ; return var_1 >= var_2 ; }
420
<awangdev>739. Daily Temperatures_2.java
public int[] dailyTemperatures(int[] T) { int n = T.length; int[] rst = new int[n]; Integer[] tempIndex = new Integer[101]; for (int i = n - 1; i >= 0; i--) { int num = T[i], warmerIndex = Integer.MAX_VALUE;; for (int t = num + 1; t <= 100; t++) { if (tempIndex[t] != null && tempIndex[t] < warmerIndex) warmerIndex = tempIndex[t]; } if (warmerIndex < Integer.MAX_VALUE) rst[i] = warmerIndex - i; tempIndex[num] = i; } return rst; }
public int [ ] sample_funcname ( int [ ] var_0 ) { int var_2 = var_0 . length ; int [ ] var_3 = new int [ var_2 ] ; Integer [ ] var_6 = new Integer [ 101 ] ; for ( int var_8 = var_2 - 1 ; var_8 >= 0 ; var_8 -- ) { int var_10 = var_0 [ var_8 ] , var_12 = Integer . MAX_VALUE ; ; for ( int var_13 = var_10 + 1 ; var_13 <= 100 ; var_13 ++ ) { if ( var_6 [ var_13 ] != null && var_6 [ var_13 ] < var_12 ) var_12 = var_6 [ var_13 ] ; } if ( var_12 < Integer . MAX_VALUE ) var_3 [ var_8 ] = var_12 - var_8 ; var_6 [ var_10 ] = var_8 ; } return var_3 ; }
421
<awangdev>1021. Remove Outermost Parentheses_1.java
private boolean isPair(char a, char b) { return a == '(' && b ==')'; }
private boolean var_0 ( char var_1 , char var_2 ) { return var_1 == '(' && var_2 == ')' ; }
422
<awangdev>Contains Duplicate III_1.java
public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) { if (nums == null || nums.length == 0 || k <= 0 || t < 0) { return false; } TreeSet<Long> treeSet = new TreeSet<>(); for (int i = 0; i < nums.length; i++) { Long target = treeSet.ceiling((long)nums[i] - t); if (target != null && target <= (long)nums[i] + t) { return true; } if (i >= k) { treeSet.remove((long)nums[i - k]); } treeSet.add((long)nums[i]); } return false; }
public boolean var_0 ( int [ ] var_1 , int var_2 , int var_3 ) { if ( var_1 == null || var_1 . length == 0 || var_2 <= 0 || var_3 < 0 ) { return false ; } TreeSet < Long > var_9 = new TreeSet < > ( ) ; for ( int var_10 = 0 ; var_10 < var_1 . length ; var_10 ++ ) { Long var_12 = var_9 . ceiling ( ( long ) var_1 [ var_10 ] - var_3 ) ; if ( var_12 != null && var_12 <= ( long ) var_1 [ var_10 ] + var_3 ) { return true ; } if ( var_10 >= var_2 ) { var_9 . remove ( ( long ) var_1 [ var_10 - var_2 ] ) ; } var_9 . add ( ( long ) var_1 [ var_10 ] ) ; } return false ; }
423
<awangdev>239. Sliding Window Maximum_3.java
private void inQueue(Deque<Integer> deque, int num) { while (!deque.isEmpty() && deque.peekLast() < num) { deque.pollLast(); } deque.offerLast(num); }
private void var_0 ( Deque < Integer > var_3 , int var_4 ) { while ( ! var_3 . isEmpty ( ) && var_3 . peekLast ( ) < var_4 ) { var_3 . pollLast ( ) ; } var_3 . offerLast ( var_4 ) ; }
424
<awangdev>Search Insert Position_1.java
public int searchInsert(int[] A, int target) { if (A == null || A.length == 0) { return 0; } int start = 0; int end = A.length - 1; int mid = start + (end - start)/2; while (start + 1 < end) { mid = start + (end - start)/2; if (A[mid] == target) { return mid; } else if (A[mid] > target) { end = mid; } else { start = mid; } } if (A[start] >= target) { return start; } else if (A[start] < target && target <= A[end]) { return end; } else { return end + 1; } }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_5 = 0 ; int var_7 = var_0 . length - 1 ; int var_9 = var_5 + ( var_7 - var_5 ) / 2 ; while ( var_5 + 1 < var_7 ) { var_9 = var_5 + ( var_7 - var_5 ) / 2 ; if ( var_0 [ var_9 ] == var_1 ) { return var_9 ; } else if ( var_0 [ var_9 ] > var_1 ) { var_7 = var_9 ; } else { var_5 = var_9 ; } } if ( var_0 [ var_5 ] >= var_1 ) { return var_5 ; } else if ( var_0 [ var_5 ] < var_1 && var_1 <= var_0 [ var_7 ] ) { return var_7 ; } else { return var_7 + 1 ; } }
425
<awangdev>788. Rotated Digits_1.java
private int[] freq(int num) { int[] count = new int[10]; while (num != 0) { count[num%10]++; num /= 10; } return count; }
private int [ ] sample_funcname ( int var_0 ) { int [ ] var_2 = new int [ 10 ] ; while ( var_0 != 0 ) { var_2 [ var_0 % 10 ] ++ ; var_0 /= 10 ; } return var_2 ; }
426
<awangdev>Reverse Words in a String II_2.java
public void reverseWords(char[] s) { if (s == null || s.length == 0) { return; } int len = s.length; for (int i = 0; i < len / 2; i++) { char temp = s[i]; s[i] = s[len - 1 - i]; s[len - 1 - i] = temp; } int start = 0; int mid = 0; int end = 0; for (int i = 0; i < len; i++) { if (s[i] == ' ') { mid = start + (end - start) / 2; for (int j = start; j <= mid; j++) { char temp = s[j]; s[j] = s[end - (j - start)]; s[end - (j - start)] = temp; } start = i + 1; } else { end = i; } } mid = start + (end - start) / 2; for (int j = start; j <= mid; j++) { char temp = s[j]; s[j] = s[end - (j - start)]; s[end - (j - start)] = temp; } }
public void var_0 ( char [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return ; } int var_5 = var_1 . length ; for ( int var_6 = 0 ; var_6 < var_5 / 2 ; var_6 ++ ) { char var_8 = var_1 [ var_6 ] ; var_1 [ var_6 ] = var_1 [ var_5 - 1 - var_6 ] ; var_1 [ var_5 - 1 - var_6 ] = var_8 ; } int var_10 = 0 ; int var_11 = 0 ; int var_12 = 0 ; for ( int var_6 = 0 ; var_6 < var_5 ; var_6 ++ ) { if ( var_1 [ var_6 ] == ' ' ) { var_11 = var_10 + ( var_12 - var_10 ) / 2 ; for ( int var_14 = var_10 ; var_14 <= var_11 ; var_14 ++ ) { char var_8 = var_1 [ var_14 ] ; var_1 [ var_14 ] = var_1 [ var_12 - ( var_14 - var_10 ) ] ; var_1 [ var_12 - ( var_14 - var_10 ) ] = var_8 ; } var_10 = var_6 + 1 ; } else { var_12 = var_6 ; } } var_11 = var_10 + ( var_12 - var_10 ) / 2 ; for ( int var_14 = var_10 ; var_14 <= var_11 ; var_14 ++ ) { char var_8 = var_1 [ var_14 ] ; var_1 [ var_14 ] = var_1 [ var_12 - ( var_14 - var_10 ) ] ; var_1 [ var_12 - ( var_14 - var_10 ) ] = var_8 ; } }
427
<awangdev>Largest Number_1.java
public String largestNumber(int[] num) { if (num == null || num.length == 0) { return ""; } String[] strs = new String[num.length]; for (int i = 0; i < num.length; i++) { strs[i] = num[i] + ""; } Arrays.sort(strs, new Comparator<String>() { public int compare(String s1, String s2) { return (s2 + s1).compareTo(s1 + s2); } }); StringBuffer sb = new StringBuffer(); for (int i = 0; i < num.length; i++) { sb.append(strs[i]); } String rst = sb.toString(); if (rst.charAt(0) == '0') { return "0"; } return rst; }
public String var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return "" ; } String [ ] var_7 = new String [ var_1 . length ] ; for ( int var_8 = 0 ; var_8 < var_1 . length ; var_8 ++ ) { var_7 [ var_8 ] = var_1 [ var_8 ] + "" ; } Arrays . sort ( var_7 , new Comparator < String > ( ) { public int compare ( String var_13 , String var_14 ) { return ( var_14 + var_13 ) . compareTo ( var_13 + var_14 ) ; } } ) ; StringBuffer var_17 = new StringBuffer ( ) ; for ( int var_8 = 0 ; var_8 < var_1 . length ; var_8 ++ ) { var_17 . append ( var_7 [ var_8 ] ) ; } String var_20 = var_17 . toString ( ) ; if ( var_20 . charAt ( 0 ) == '0' ) { return "0" ; } return var_20 ; }
428
<awangdev>Majority Number III_1.java
public int majorityNumber(ArrayList<Integer> nums, int k) { if (nums == null || nums.size() == 0) { return -1; } HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for (Integer num : nums) { if (map.containsKey(num)) { map.put(num, map.get(num) + 1); } else { if (map.size() == k) { Iterator<Map.Entry<Integer, Integer>> iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Integer, Integer> entry = iter.next(); if (entry.getValue() - 1 == 0) { iter.remove(); } else { map.put(entry.getKey(), entry.getValue() - 1); } } } else { map.put(num, 1); } } } int result = 0; int max = 0; for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getValue() > max) { max = entry.getValue(); result = entry.getKey(); } } return result; }
public int sample_funcname ( ArrayList < Integer > var_2 , int var_3 ) { if ( var_2 == null || var_2 . size ( ) == 0 ) { return - 1 ; } HashMap < Integer , Integer > var_9 = new HashMap < Integer , Integer > ( ) ; for ( Integer var_10 : var_2 ) { if ( var_9 . containsKey ( var_10 ) ) { var_9 . put ( var_10 , var_9 . get ( var_10 ) + 1 ) ; } else { if ( var_9 . size ( ) == var_3 ) { Iterator < Map . Entry < Integer , Integer >> var_19 = var_9 . entrySet ( ) . iterator ( ) ; while ( var_19 . hasNext ( ) ) { Map . Entry < Integer , Integer > var_22 = var_19 . next ( ) ; if ( var_22 . getValue ( ) - 1 == 0 ) { var_19 . remove ( ) ; } else { var_9 . put ( var_22 . getKey ( ) , var_22 . getValue ( ) - 1 ) ; } } } else { var_9 . put ( var_10 , 1 ) ; } } } int var_26 = 0 ; int var_27 = 0 ; for ( Map . Entry < Integer , Integer > var_22 : var_9 . entrySet ( ) ) { if ( var_22 . getValue ( ) > var_27 ) { var_27 = var_22 . getValue ( ) ; var_26 = var_22 . getKey ( ) ; } } return var_26 ; }
429
<awangdev>Number Of Corner Rectangles_1.java
private boolean validate(int[][] grid) { return grid == null || grid.length == 0 || grid[0] == null || grid[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 ; }
430
<awangdev>Subarray Sum Closest_1.java
public int compare(int[] a, int[] b) { return Integer.compare(a[0], b[0]); }
public int sample_funcname ( int [ ] var_0 , int [ ] var_1 ) { return Integer . compare ( var_0 [ 0 ] , var_1 [ 0 ] ) ; }
431
<awangdev>Distinct Subsequences_1.java
public int numDistinct(String s, String t) { if (s == null || t == null || t.length() > s.length()) { return 0; } else if (s.equals(t)) { return 1; } int m = s.length(); int n = t.length(); int[][] dp = new int[m + 1][n + 1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (j == 0) { dp[i][j] = 1; continue; } if (i == 0) { dp[i][j] = 0; continue; } dp[i][j] = dp[i - 1][j]; if (s.charAt(i - 1) == t.charAt(j - 1)) { dp[i][j] += dp[i - 1][j - 1]; } } } return dp[m][n]; }
public int sample_funcname ( String var_1 , String var_2 ) { if ( var_1 == null || var_2 == null || var_2 . length ( ) > var_1 . length ( ) ) { return 0 ; } else if ( var_1 . equals ( var_2 ) ) { return 1 ; } int var_8 = var_1 . length ( ) ; int var_9 = var_2 . length ( ) ; int [ ] [ ] var_10 = new int [ var_8 + 1 ] [ var_9 + 1 ] ; for ( int var_11 = 0 ; var_11 <= var_8 ; var_11 ++ ) { for ( int var_12 = 0 ; var_12 <= var_9 ; var_12 ++ ) { if ( var_12 == 0 ) { var_10 [ var_11 ] [ var_12 ] = 1 ; continue ; } if ( var_11 == 0 ) { var_10 [ var_11 ] [ var_12 ] = 0 ; continue ; } var_10 [ var_11 ] [ var_12 ] = var_10 [ var_11 - 1 ] [ var_12 ] ; if ( var_1 . charAt ( var_11 - 1 ) == var_2 . charAt ( var_12 - 1 ) ) { var_10 [ var_11 ] [ var_12 ] += var_10 [ var_11 - 1 ] [ var_12 - 1 ] ; } } } return var_10 [ var_8 ] [ var_9 ] ; }
432
<awangdev>140. Word Break II_1.java
private String output(List<String> list) { StringBuffer sb = new StringBuffer(); for (String s : list) sb.append(s).append(" "); return sb.toString().trim(); }
private String var_0 ( List < String > var_3 ) { StringBuffer var_5 = new StringBuffer ( ) ; for ( String var_6 : var_3 ) var_5 . append ( var_6 ) . append ( " " ) ; return var_5 . toString ( ) . trim ( ) ; }
433
<awangdev>689. Maximum Sum of 3 Non-Overlapping Subarrays_1.java
private int[] calcLeft(int[] nums, int[] presum, int k) { int n = nums.length; int[] left = new int[n]; for (int i = k, total = presum[k] - presum[0]; i < n; i++) { int sum = presum[i + 1] - presum[i + 1 - k]; if (sum > total) { left[i] = i + 1 - k; total = sum; } else left[i] = left[i - 1]; } return left; }
private int [ ] sample_funcname ( int [ ] var_0 , int [ ] var_1 , int var_2 ) { int var_4 = var_0 . length ; int [ ] var_5 = new int [ var_4 ] ; for ( int var_6 = var_2 , var_8 = var_1 [ var_2 ] - var_1 [ 0 ] ; var_6 < var_4 ; var_6 ++ ) { int var_10 = var_1 [ var_6 + 1 ] - var_1 [ var_6 + 1 - var_2 ] ; if ( var_10 > var_8 ) { var_5 [ var_6 ] = var_6 + 1 - var_2 ; var_8 = var_10 ; } else var_5 [ var_6 ] = var_5 [ var_6 - 1 ] ; } return var_5 ; }
434
<awangdev>Counting Bits_2.java
public int[] countBits(int num) { if (num < 0) { return null; } int[] dp = new int[num + 1]; dp[0] = 0; for (int i = 1; i <= num; i++) { int prevNum = i >> 1; dp[i] = dp[prevNum] + (i & 1); } return dp; }
public int [ ] sample_funcname ( int var_0 ) { if ( var_0 < 0 ) { return null ; } int [ ] var_4 = new int [ var_0 + 1 ] ; var_4 [ 0 ] = 0 ; for ( int var_5 = 1 ; var_5 <= var_0 ; var_5 ++ ) { int var_6 = var_5 >> 1 ; var_4 [ var_5 ] = var_4 [ var_6 ] + ( var_5 & 1 ) ; } return var_4 ; }
435
<awangdev>301. Remove Invalid Parentheses_1.java
private void dfs(List<String> rst, String s, int i, int j, char open, char close) { for (int count = 0; i < s.length(); i++) { count += s.charAt(i) == open ? 1 : 0; count -= s.charAt(i) == close ? 1 : 0; if (count < 0) { int init = j; for (; j <= i; j++) { if (s.charAt(j) == close && (j == init || s.charAt(j) != s.charAt(j - 1))) { dfs(rst, s.substring(0, j) + s.substring(j + 1), i, j, open, close); } } return; } } String reversed = new StringBuffer(s).reverse().toString(); if (open == '(') { dfs(rst, reversed, 0, 0, close, open); } else { rst.add(reversed); } }
private void sample_funcname ( List < String > rst , String s , int i , int j , char open , char close ) { for ( int count = 0 ; i < s . length ( ) ; i ++ ) { count += s . charAt ( i ) == open ? 1 : 0 ; count -= s . charAt ( i ) == close ? 1 : 0 ; if ( count < 0 ) { int init = j ; for ( ; j <= i ; j ++ ) { if ( s . charAt ( j ) == close && ( j == init || s . charAt ( j ) != s . charAt ( j - 1 ) ) ) { dfs ( rst , s . substring ( 0 , j ) + s . substring ( j + 1 ) , i , j , open , close ) ; } } return ; } } String reversed = new StringBuffer ( s ) . reverse ( ) . toString ( ) ; if ( open == '(' ) { dfs ( rst , reversed , 0 , 0 , close , open ) ; } else { rst . add ( reversed ) ; } }
436
<awangdev>43. Multiply Strings_4.java
private int toInt(String s, int x) { return s.charAt(x) - '0'; }
private int sample_funcname ( String var_1 , int var_2 ) { return var_1 . charAt ( var_2 ) - '0' ; }
437
<awangdev>Coins in a Line_1.java
public boolean firstWillWin(int n) { if (n <= 0) { return false; } boolean[] dp = new boolean[n + 1]; dp[0] = false; dp[1] = true; for (int i = 2; i <= n; i++) { dp[i] = !dp[i - 2] || !dp[i - 1]; } return dp[n]; }
public boolean var_0 ( int var_1 ) { if ( var_1 <= 0 ) { return false ; } boolean [ ] var_5 = new boolean [ var_1 + 1 ] ; var_5 [ 0 ] = false ; var_5 [ 1 ] = true ; for ( int var_7 = 2 ; var_7 <= var_1 ; var_7 ++ ) { var_5 [ var_7 ] = ! var_5 [ var_7 - 2 ] || ! var_5 [ var_7 - 1 ] ; } return var_5 [ var_1 ] ; }
438
<awangdev>785. Is Graph Bipartite_2.java
public boolean isBipartite(int[][] graph) { int n = graph.length; Boolean[] states = new Boolean[n]; for (int i = 0; i < n; i++) { if (states[i] != null) continue; Queue<Integer> queue = new LinkedList<Integer>(); queue.offer(i); states[i] = true; while (!queue.isEmpty()) { int curr = queue.poll(); for (int next : graph[curr]) { if (states[next] != null) { if (states[next] == states[curr]) return false; continue; } states[next] = !states[curr]; queue.offer(next); } } } return true; }
public boolean var_0 ( int [ ] [ ] var_1 ) { int var_3 = var_1 . length ; Boolean [ ] var_5 = new Boolean [ var_3 ] ; for ( int var_7 = 0 ; var_7 < var_3 ; var_7 ++ ) { if ( var_5 [ var_7 ] != null ) continue ; Queue < Integer > var_12 = new LinkedList < Integer > ( ) ; var_12 . offer ( var_7 ) ; var_5 [ var_7 ] = true ; while ( ! var_12 . isEmpty ( ) ) { int var_16 = var_12 . poll ( ) ; for ( int var_17 : var_1 [ var_16 ] ) { if ( var_5 [ var_17 ] != null ) { if ( var_5 [ var_17 ] == var_5 [ var_16 ] ) return false ; continue ; } var_5 [ var_17 ] = ! var_5 [ var_16 ] ; var_12 . offer ( var_17 ) ; } } } return true ; }
439
<awangdev>Trapping Rain Water II_3.java
public int trapRainWater(int[][] heightMap) { if (heightMap == null || heightMap.length == 0 || heightMap[0] == null || heightMap[0].length == 0) { return 0; } int m = heightMap.length; int n = heightMap[0].length; int[][] maxLeft = new int[m][n]; int[][] maxRight = new int[m][n]; int[][] maxUp = new int[m][n]; int[][] maxDown = new int[m][n]; for (int i = 0; i < m; i++) { maxLeft[i][0] = heightMap[i][0]; maxRight[i][n - 1] = heightMap[i][n - 1]; } for (int j = 0; j < n; j++) { maxUp[0][j] = heightMap[0][j]; maxDown[m - 1][j] = heightMap[m - 1][j]; } for (int i = 0; i < m; i++) { for (int j = 1; j < n; j++) { maxLeft[i][j] = Math.max(maxLeft[i][j - 1], heightMap[i][j]); maxRight[i][n - j - 1] = Math.max(maxRight[i][n - j], heightMap[i][n - j - 1]); } } for (int j = 0; j < n; j++) { for (int i = 1; i < m; i++) { maxUp[i][j] = Math.max(maxUp[i - 1][j], heightMap[i][j]); maxDown[m - i - 1][j] = Math.max(maxDown[m - i][j], heightMap[m - i - 1][j]); } } int total = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int lowestHeight = Math.min(Math.min(maxLeft[i][j], maxRight[i][j]), Math.min(maxUp[i][j], maxDown[i][j])); total += lowestHeight > heightMap[i][j] ? lowestHeight - heightMap[i][j] : 0; } } return total; }
public int sample_funcname ( int [ ] [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 || var_0 [ 0 ] == null || var_0 [ 0 ] . length == 0 ) { return 0 ; } int var_4 = var_0 . length ; int var_5 = var_0 [ 0 ] . length ; int [ ] [ ] var_6 = new int [ var_4 ] [ var_5 ] ; int [ ] [ ] var_7 = new int [ var_4 ] [ var_5 ] ; int [ ] [ ] var_8 = new int [ var_4 ] [ var_5 ] ; int [ ] [ ] var_9 = new int [ var_4 ] [ var_5 ] ; for ( int var_10 = 0 ; var_10 < var_4 ; var_10 ++ ) { var_6 [ var_10 ] [ 0 ] = var_0 [ var_10 ] [ 0 ] ; var_7 [ var_10 ] [ var_5 - 1 ] = var_0 [ var_10 ] [ var_5 - 1 ] ; } for ( int var_12 = 0 ; var_12 < var_5 ; var_12 ++ ) { var_8 [ 0 ] [ var_12 ] = var_0 [ 0 ] [ var_12 ] ; var_9 [ var_4 - 1 ] [ var_12 ] = var_0 [ var_4 - 1 ] [ var_12 ] ; } for ( int var_10 = 0 ; var_10 < var_4 ; var_10 ++ ) { for ( int var_12 = 1 ; var_12 < var_5 ; var_12 ++ ) { var_6 [ var_10 ] [ var_12 ] = Math . max ( var_6 [ var_10 ] [ var_12 - 1 ] , var_0 [ var_10 ] [ var_12 ] ) ; var_7 [ var_10 ] [ var_5 - var_12 - 1 ] = Math . max ( var_7 [ var_10 ] [ var_5 - var_12 ] , var_0 [ var_10 ] [ var_5 - var_12 - 1 ] ) ; } } for ( int var_12 = 0 ; var_12 < var_5 ; var_12 ++ ) { for ( int var_10 = 1 ; var_10 < var_4 ; var_10 ++ ) { var_8 [ var_10 ] [ var_12 ] = Math . max ( var_8 [ var_10 - 1 ] [ var_12 ] , var_0 [ var_10 ] [ var_12 ] ) ; var_9 [ var_4 - var_10 - 1 ] [ var_12 ] = Math . max ( var_9 [ var_4 - var_10 ] [ var_12 ] , var_0 [ var_4 - var_10 - 1 ] [ var_12 ] ) ; } } int var_15 = 0 ; for ( int var_10 = 0 ; var_10 < var_4 ; var_10 ++ ) { for ( int var_12 = 0 ; var_12 < var_5 ; var_12 ++ ) { int var_17 = Math . min ( Math . min ( var_6 [ var_10 ] [ var_12 ] , var_7 [ var_10 ] [ var_12 ] ) , Math . min ( var_8 [ var_10 ] [ var_12 ] , var_9 [ var_10 ] [ var_12 ] ) ) ; var_15 += var_17 > var_0 [ var_10 ] [ var_12 ] ? var_17 - var_0 [ var_10 ] [ var_12 ] : 0 ; } } return var_15 ; }
440
<awangdev>Permutation Index_1.java
public long permutationIndex(int[] A) { if (A == null || A.length == 0) { return 0; } HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int n = A.length; long rst = 0; for (int i = 0; i < n; i++) { int count = 0; for (int j = i + 1; j < n; j++) { if (A[j] < A[i]) { count++; } } map.put(A[i], count); } for (int i = 0; i < n; i++) { long fact = 1; for (int j = (n - i - 1); j >= 1; j--) { fact *= j; } rst += map.get(A[i]) * fact; } return rst + 1; }
public long sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } HashMap < Integer , Integer > var_6 = new HashMap < Integer , Integer > ( ) ; int var_7 = var_0 . length ; long var_8 = 0 ; for ( int var_9 = 0 ; var_9 < var_7 ; var_9 ++ ) { int var_10 = 0 ; for ( int var_12 = var_9 + 1 ; var_12 < var_7 ; var_12 ++ ) { if ( var_0 [ var_12 ] < var_0 [ var_9 ] ) { var_10 ++ ; } } var_6 . put ( var_0 [ var_9 ] , var_10 ) ; } for ( int var_9 = 0 ; var_9 < var_7 ; var_9 ++ ) { long var_14 = 1 ; for ( int var_12 = ( var_7 - var_9 - 1 ) ; var_12 >= 1 ; var_12 -- ) { var_14 *= var_12 ; } var_8 += var_6 . get ( var_0 [ var_9 ] ) * var_14 ; } return var_8 + 1 ; }
441
<awangdev>1108. Defanging an IP Address_1.java
public String defangIPaddr(String address) { StringBuffer sb = new StringBuffer(); for (char c : address.toCharArray()) { if (c == '.') { sb.append("[.]"); } else { sb.append(c); } } return sb.toString(); }
public String var_0 ( String var_2 ) { StringBuffer var_4 = new StringBuffer ( ) ; for ( char var_6 : var_2 . toCharArray ( ) ) { if ( var_6 == '.' ) { var_4 . append ( "[.]" ) ; } else { var_4 . append ( var_6 ) ; } } return var_4 . toString ( ) ; }
442
<awangdev>Trapping Rain Water II_2.java
private boolean isInvalid(int[][] heightMap) { return heightMap == null || heightMap.length == 0 || heightMap[0] == null || heightMap[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 ; }
443
<awangdev>63. Unique Paths II_1.java
public int uniquePathsWithObstacles(int[][] obstacleGrid) { if (obstacleGrid == null || obstacleGrid.length == 0) return 0; int m = obstacleGrid.length, n = obstacleGrid[0].length; int[][] dp = new int[m][n]; for (int i = 0, j = 0; j < n; j++) { if (obstacleGrid[i][j] == 1) break; dp[i][j] = 1; } for (int i = 0, j = 0; i < m; i++) { if (obstacleGrid[i][j] == 1) break; dp[i][j] = 1; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { if (obstacleGrid[i][j] == 1) continue; dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } } return dp[m - 1][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 , var_5 = var_0 [ 0 ] . length ; int [ ] [ ] var_6 = new int [ var_4 ] [ var_5 ] ; for ( int var_7 = 0 , var_8 = 0 ; var_8 < var_5 ; var_8 ++ ) { if ( var_0 [ var_7 ] [ var_8 ] == 1 ) break ; var_6 [ var_7 ] [ var_8 ] = 1 ; } for ( int var_7 = 0 , var_8 = 0 ; var_7 < var_4 ; var_7 ++ ) { if ( var_0 [ var_7 ] [ var_8 ] == 1 ) break ; var_6 [ var_7 ] [ var_8 ] = 1 ; } for ( int var_7 = 1 ; var_7 < var_4 ; var_7 ++ ) { for ( int var_8 = 1 ; var_8 < var_5 ; var_8 ++ ) { if ( var_0 [ var_7 ] [ var_8 ] == 1 ) continue ; var_6 [ var_7 ] [ var_8 ] = var_6 [ var_7 - 1 ] [ var_8 ] + var_6 [ var_7 ] [ var_8 - 1 ] ; } } return var_6 [ var_4 - 1 ] [ var_5 - 1 ] ; }
444
<awangdev>322. Coin Change_1.java
public int coinChange(int[] coins, int amount) { int[] dp = new int[amount + 1]; dp[0] = 0; for (int i = 1; i <= amount; i++) { dp[i] = Integer.MAX_VALUE; for (int coin : coins) { if (coin > i || dp[i - coin] == Integer.MAX_VALUE) continue; dp[i] = Math.min(dp[i], dp[i - coin] + 1); } } return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount]; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { int [ ] var_3 = new int [ var_1 + 1 ] ; var_3 [ 0 ] = 0 ; for ( int var_5 = 1 ; var_5 <= var_1 ; var_5 ++ ) { var_3 [ var_5 ] = Integer . MAX_VALUE ; for ( int var_8 : var_0 ) { if ( var_8 > var_5 || var_3 [ var_5 - var_8 ] == Integer . MAX_VALUE ) continue ; var_3 [ var_5 ] = Math . min ( var_3 [ var_5 ] , var_3 [ var_5 - var_8 ] + 1 ) ; } } return var_3 [ var_1 ] == Integer . MAX_VALUE ? - 1 : var_3 [ var_1 ] ; }
445
<awangdev>Word Ladder II_2.java
public ArrayList<String> expand(String str, Set<String> dict) { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < str.length(); i++) { for (int j = 0; j < 26; j++) { if (str.charAt(i) != (char)('a' + j)) { String newStr = str.substring(0, i) + (char)('a' + j) + str.substring(i + 1); if (dict.contains(newStr)) { list.add(newStr); } } } } return list; }
public ArrayList < String > var_1 ( String var_2 , Set < String > var_4 ) { ArrayList < String > var_6 = new ArrayList < String > ( ) ; for ( int var_8 = 0 ; var_8 < var_2 . length ( ) ; var_8 ++ ) { for ( int var_10 = 0 ; var_10 < 26 ; var_10 ++ ) { if ( var_2 . charAt ( var_8 ) != ( char ) ( 'a' + var_10 ) ) { String var_16 = var_2 . substring ( 0 , var_8 ) + ( char ) ( 'a' + var_10 ) + var_2 . substring ( var_8 + 1 ) ; if ( var_4 . contains ( var_16 ) ) { var_6 . add ( var_16 ) ; } } } } return var_6 ; }
446
<awangdev>245. Shortest Word Distance III_2.java
public int shortestWordDistance(String[] words, String word1, String word2) { Map<String, List<Integer>> map = new HashMap<>(); for (int i = 0; i < words.length; i++) { map.putIfAbsent(words[i], new ArrayList<>()); map.get(words[i]).add(i); } List<Integer> list1 = map.get(word1), list2 = map.get(word2); int min = Integer.MAX_VALUE; int i = 0, j = 0, m = list1.size(), n = list2.size(); while (i < m && j < n) { int p1 = list1.get(i), p2 = list2.get(j); if (p1 == p2) { if (i + 1 < m) i++; else if (j + 1 <= n) j++; continue; } min = Math.min(min, Math.abs(p1 - p2)); if (p1 < p2) i++; else j++; } return min; }
public int sample_funcname ( String [ ] var_1 , String var_2 , String var_3 ) { Map < String , List < Integer >> var_8 = new HashMap < > ( ) ; for ( int var_10 = 0 ; var_10 < var_1 . length ; var_10 ++ ) { var_8 . putIfAbsent ( var_1 [ var_10 ] , new ArrayList < > ( ) ) ; var_8 . get ( var_1 [ var_10 ] ) . add ( var_10 ) ; } List < Integer > var_16 = var_8 . get ( var_2 ) , var_17 = var_8 . get ( var_3 ) ; int min = Integer . MAX_VALUE ; int var_10 = 0 , var_20 = 0 , var_22 = var_16 . size ( ) , var_23 = var_17 . size ( ) ; while ( var_10 < var_22 && var_20 < var_23 ) { int var_24 = var_16 . get ( var_10 ) , var_25 = var_17 . get ( var_20 ) ; if ( var_24 == var_25 ) { if ( var_10 + 1 < var_22 ) var_10 ++ ; else if ( var_20 + 1 <= var_23 ) var_20 ++ ; continue ; } min = Math . min ( min , Math . abs ( var_24 - var_25 ) ) ; if ( var_24 < var_25 ) var_10 ++ ; else var_20 ++ ; } return min ; }
447
<awangdev>43. Multiply Strings_5.java
public String multiply(String num1, String num2) { if (num1 == null || num2 == null) { return ""; } else if (num1.length() == 0 || num2.length() == 0) { return num1.length() == 0 ? num2 : num1; } else if (num1.equals("0") || num2.equals("0")) { return "0"; } num1 = new StringBuffer(num1).reverse().toString(); num2 = new StringBuffer(num2).reverse().toString(); int[] product = new int[num1.length() + num2.length()]; for (int i = 0; i < num1.length(); i++) { int a = num1.charAt(i) - '0'; for (int j = 0; j < num2.length(); j++) { int b = num2.charAt(j) - '0'; product[i + j] += a * b; } } StringBuffer sb = new StringBuffer(); for (int i = 0; i < product.length; i++) { int number = product[i] % 10; int carrier = product[i] / 10; sb.append(number); if (i < product.length - 1) { product[i + 1] += carrier; } } sb.reverse(); while (sb.length() > 0 && sb.charAt(0) == '0') { sb.deleteCharAt(0); } return sb.toString(); }
public String var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_3 == null ) { return "" ; } else if ( var_2 . length ( ) == 0 || var_3 . length ( ) == 0 ) { return var_2 . length ( ) == 0 ? var_3 : var_2 ; } else if ( var_2 . equals ( "0" ) || var_3 . equals ( "0" ) ) { return "0" ; } var_2 = new StringBuffer ( var_2 ) . reverse ( ) . toString ( ) ; var_3 = new StringBuffer ( var_3 ) . reverse ( ) . toString ( ) ; int [ ] var_13 = new int [ var_2 . length ( ) + var_3 . length ( ) ] ; for ( int var_14 = 0 ; var_14 < var_2 . length ( ) ; var_14 ++ ) { int var_17 = var_2 . charAt ( var_14 ) - '0' ; for ( int var_18 = 0 ; var_18 < var_3 . length ( ) ; var_18 ++ ) { int var_19 = var_3 . charAt ( var_18 ) - '0' ; var_13 [ var_14 + var_18 ] += var_17 * var_19 ; } } StringBuffer var_20 = new StringBuffer ( ) ; for ( int var_14 = 0 ; var_14 < var_13 . length ; var_14 ++ ) { int var_22 = var_13 [ var_14 ] % 10 ; int var_23 = var_13 [ var_14 ] / 10 ; var_20 . append ( var_22 ) ; if ( var_14 < var_13 . length - 1 ) { var_13 [ var_14 + 1 ] += var_23 ; } } var_20 . reverse ( ) ; while ( var_20 . length ( ) > 0 && var_20 . charAt ( 0 ) == '0' ) { var_20 . deleteCharAt ( 0 ) ; } return var_20 . toString ( ) ; }
448
<awangdev>373. Find K Pairs with Smallest Sums_2.java
private PriorityQueue<List<Integer>> initQueue(int k) { return new PriorityQueue<>(k, new Comparator<List<Integer>>() { public int compare(List<Integer> a, List<Integer> b) { return b.get(0) + b.get(1) - a.get(0) - a.get(1); } }); }
private PriorityQueue < List < Integer >> var_2 ( int var_3 ) { return new PriorityQueue < > ( var_3 , new Comparator < List < Integer >> ( ) { public int compare ( List < Integer > var_7 , List < Integer > var_8 ) { return var_8 . get ( 0 ) + var_8 . get ( 1 ) - var_7 . get ( 0 ) - var_7 . get ( 1 ) ; } } ) ; }
449
<awangdev>34. Find First and Last Position of Element in Sorted Array_2.java
private int binarySearch(int[] nums, int target, boolean isLeft) { int n = nums.length, start = 0, end = n - 1; while (start + 1 < end) { int mid = start + (end - start) / 2, val = nums[mid]; if (val == target) { if (isLeft && mid - 1 >= 0 && nums[mid - 1] == target) end = mid; else if (!isLeft && mid + 1 <= n - 1 && nums[mid + 1] == target) start = mid; else return mid; } else if (val < target) start = mid; else end = mid; } if (nums[start] == target && nums[end] == target) return isLeft ? start : end; if (nums[start] == target) return start; if (nums[end] == target) return end; return -1; }
private int sample_funcname ( int [ ] var_0 , int var_1 , boolean var_3 ) { int var_5 = var_0 . length , var_7 = 0 , var_9 = var_5 - 1 ; while ( var_7 + 1 < var_9 ) { int var_11 = var_7 + ( var_9 - var_7 ) / 2 , var_12 = var_0 [ var_11 ] ; if ( var_12 == var_1 ) { if ( var_3 && var_11 - 1 >= 0 && var_0 [ var_11 - 1 ] == var_1 ) var_9 = var_11 ; else if ( ! var_3 && var_11 + 1 <= var_5 - 1 && var_0 [ var_11 + 1 ] == var_1 ) var_7 = var_11 ; else return var_11 ; } else if ( var_12 < var_1 ) var_7 = var_11 ; else var_9 = var_11 ; } if ( var_0 [ var_7 ] == var_1 && var_0 [ var_9 ] == var_1 ) return var_3 ? var_7 : var_9 ; if ( var_0 [ var_7 ] == var_1 ) return var_7 ; if ( var_0 [ var_9 ] == var_1 ) return var_9 ; return - 1 ; }
450
<awangdev>49. Group Anagrams_1.java
private String getKey(String s) { int[] count = new int[26]; for (char c : s.toCharArray()) count[c - 'a']++; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 26; i++) sb.append(count[i]); return sb.toString(); }
private String var_0 ( String var_2 ) { int [ ] var_4 = new int [ 26 ] ; for ( char var_6 : var_2 . toCharArray ( ) ) var_4 [ var_6 - 'a' ] ++ ; StringBuilder var_9 = new StringBuilder ( ) ; for ( int var_11 = 0 ; var_11 < 26 ; var_11 ++ ) var_9 . append ( var_4 [ var_11 ] ) ; return var_9 . toString ( ) ; }
451
<awangdev>516. Longest Palindromic Subsequence_2.java
public int longestPalindromeSubseq(String s) { char[] ss = s.toCharArray(); int n = s.length(); int[][] dp = new int[n][n]; for (int i = 0; i < n; i++) dp[i][i] = 1; for (int i = 0; i < n - 1; i++) dp[i][i + 1] = ss[i] == ss[i + 1] ? 2 : 1; for (int len = 3; len <= n; len++) { for (int i = 0; i <= n - len; i++) { int j = len + i - 1; dp[i][j] = Math.max(dp[i + 1][j], dp[i][j - 1]); if (ss[i] == ss[j]) dp[i][j] = Math.max(dp[i][j], dp[i + 1][j - 1] + 2); } } return dp[0][n - 1]; }
public int sample_funcname ( String var_1 ) { char [ ] var_3 = var_1 . toCharArray ( ) ; int var_5 = var_1 . length ( ) ; int [ ] [ ] var_6 = new int [ var_5 ] [ var_5 ] ; for ( int var_8 = 0 ; var_8 < var_5 ; var_8 ++ ) var_6 [ var_8 ] [ var_8 ] = 1 ; for ( int var_8 = 0 ; var_8 < var_5 - 1 ; var_8 ++ ) var_6 [ var_8 ] [ var_8 + 1 ] = var_3 [ var_8 ] == var_3 [ var_8 + 1 ] ? 2 : 1 ; for ( int var_12 = 3 ; var_12 <= var_5 ; var_12 ++ ) { for ( int var_8 = 0 ; var_8 <= var_5 - var_12 ; var_8 ++ ) { int var_13 = var_12 + var_8 - 1 ; var_6 [ var_8 ] [ var_13 ] = Math . max ( var_6 [ var_8 + 1 ] [ var_13 ] , var_6 [ var_8 ] [ var_13 - 1 ] ) ; if ( var_3 [ var_8 ] == var_3 [ var_13 ] ) var_6 [ var_8 ] [ var_13 ] = Math . max ( var_6 [ var_8 ] [ var_13 ] , var_6 [ var_8 + 1 ] [ var_13 - 1 ] + 2 ) ; } } return var_6 [ 0 ] [ var_5 - 1 ] ; }
452
<awangdev>239. Sliding Window Maximum_2.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 ( ) ; }
453
<awangdev>414. Third Maximum Number_1.java
public int thirdMax(int[] nums) { PriorityQueue<Integer> pq = new PriorityQueue<>(); for (int num : nums) { if (!pq.contains(num)) { pq.offer(num); if (pq.size() > 3) pq.poll(); } } if (pq.size() < 3) { while (pq.size() > 1) pq.poll(); } return pq.peek(); }
public int sample_funcname ( int [ ] var_0 ) { PriorityQueue < Integer > var_3 = new PriorityQueue < > ( ) ; for ( int var_4 : var_0 ) { if ( ! var_3 . contains ( var_4 ) ) { var_3 . offer ( var_4 ) ; if ( var_3 . size ( ) > 3 ) var_3 . poll ( ) ; } } if ( var_3 . size ( ) < 3 ) { while ( var_3 . size ( ) > 1 ) var_3 . poll ( ) ; } return var_3 . peek ( ) ; }
454
<awangdev>Total Occurrence of Target_1.java
public int totalOccurrence(int[] A, int target) { if (A == null || A.length == 0) { return 0; } int start = 0; int end = A.length - 1; int mid = start + (end - start)/2; int first = 0; int last = 0; while (start + 1 < end){ mid = start + (end - start)/2; if (A[mid] == target) { if (mid - 1 >= 0 && A[mid - 1] == target) { end = mid; } else { break; } } else if (A[mid] < target) { start = mid; } else { end = mid; } } if (A[start] == target) { first = start; } else if (A[mid] == target){ first = mid; } else if (A[end] == target){ first = end; } else { return 0; } if (mid + 1 < A.length && A[mid + 1] != target) { return 1; } start = first; last = start + 1; end = A.length - 1; while (start + 1 < end){ mid = start + (end - start)/2; if (A[mid] == target) { if (mid + 1 < A.length && A[mid + 1] == target) { start = mid; } else { break; } } else if (A[mid] < target) { start = mid; } else { end = mid; } } if (A[end] == target) { last = end; } else if (A[mid] == target){ last = mid; } else if (A[start] == target) { last = start; } return last - first + 1; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_5 = 0 ; int var_7 = var_0 . length - 1 ; int var_9 = var_5 + ( var_7 - var_5 ) / 2 ; int var_10 = 0 ; int var_11 = 0 ; while ( var_5 + 1 < var_7 ) { var_9 = var_5 + ( var_7 - var_5 ) / 2 ; if ( var_0 [ var_9 ] == var_1 ) { if ( var_9 - 1 >= 0 && var_0 [ var_9 - 1 ] == var_1 ) { var_7 = var_9 ; } else { break ; } } else if ( var_0 [ var_9 ] < var_1 ) { var_5 = var_9 ; } else { var_7 = var_9 ; } } if ( var_0 [ var_5 ] == var_1 ) { var_10 = var_5 ; } else if ( var_0 [ var_9 ] == var_1 ) { var_10 = var_9 ; } else if ( var_0 [ var_7 ] == var_1 ) { var_10 = var_7 ; } else { return 0 ; } if ( var_9 + 1 < var_0 . length && var_0 [ var_9 + 1 ] != var_1 ) { return 1 ; } var_5 = var_10 ; var_11 = var_5 + 1 ; var_7 = var_0 . length - 1 ; while ( var_5 + 1 < var_7 ) { var_9 = var_5 + ( var_7 - var_5 ) / 2 ; if ( var_0 [ var_9 ] == var_1 ) { if ( var_9 + 1 < var_0 . length && var_0 [ var_9 + 1 ] == var_1 ) { var_5 = var_9 ; } else { break ; } } else if ( var_0 [ var_9 ] < var_1 ) { var_5 = var_9 ; } else { var_7 = var_9 ; } } if ( var_0 [ var_7 ] == var_1 ) { var_11 = var_7 ; } else if ( var_0 [ var_9 ] == var_1 ) { var_11 = var_9 ; } else if ( var_0 [ var_5 ] == var_1 ) { var_11 = var_5 ; } return var_11 - var_10 + 1 ; }
455
<awangdev>Binary Gap_1.java
public int binaryGap(int N) { if (N <= 0) return 0; int max = 0, start = -1, end = 0; while (N > 0) { if ((N & 1) == 1) { if (start == -1) start = end; else { max = Math.max(max, end - start); start = end; } } end++; N = N >> 1; } return max; }
public int sample_funcname ( int var_0 ) { if ( var_0 <= 0 ) return 0 ; int max = 0 , var_4 = - 1 , var_5 = 0 ; while ( var_0 > 0 ) { if ( ( var_0 & 1 ) == 1 ) { if ( var_4 == - 1 ) var_4 = var_5 ; else { max = Math . max ( max , var_5 - var_4 ) ; var_4 = var_5 ; } } var_5 ++ ; var_0 = var_0 >> 1 ; } return max ; }
456
<awangdev>Space Replacement_1.java
public int replaceBlank(char[] string, int length) { if (string == null || string.length == 0) { return 0; } int count = 0; for (char c : string) { if (c == ' ') { count += 2; } } int lastIndex = length + count - 1; for (int i = length - 1; i >= 0; i--) { if (string[i] == ' ') { string[lastIndex--] = '0'; string[lastIndex--] = '2'; string[lastIndex--] = '%'; } else { string[lastIndex--] = string[i]; } } return length + count; }
public int sample_funcname ( char [ ] var_0 , int length ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = 0 ; for ( char var_5 : var_0 ) { if ( var_5 == ' ' ) { var_4 += 2 ; } } int var_9 = length + var_4 - 1 ; for ( int var_10 = length - 1 ; var_10 >= 0 ; var_10 -- ) { if ( var_0 [ var_10 ] == ' ' ) { var_0 [ var_9 -- ] = '0' ; var_0 [ var_9 -- ] = '2' ; var_0 [ var_9 -- ] = '%' ; } else { var_0 [ var_9 -- ] = var_0 [ var_10 ] ; } } return length + var_4 ; }
457
<awangdev>274.H-Index_4.java
public int hIndex(int[] citations) { if (citations == null || citations.length == 0) { return 0; } int n = citations.length; Arrays.sort(citations); for (int i = 0; i < n; i++) { int h = n - i; if (citations[i] >= h) { return h; } } 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 ; Arrays . sort ( var_0 ) ; for ( int var_7 = 0 ; var_7 < var_4 ; var_7 ++ ) { int var_8 = var_4 - var_7 ; if ( var_0 [ var_7 ] >= var_8 ) { return var_8 ; } } return 0 ; }
458
<awangdev>8. String to Integer (atoi)_1.java
private boolean isDigit(char c) { return c >= '0' && c <= '9'; }
private boolean var_0 ( char var_1 ) { return var_1 >= '0' && var_1 <= '9' ; }
459
<awangdev>Best Time to Buy and Sell Stock III_1.java
public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) { return 0; } int profit = 0; int n = prices.length; int[][] dp = new int[n][5]; dp[0][0] = 0; for (int i = 1; i < n; i++) { for (int j = 1; j < 5; j++) { int dailyDiff = prices[i] - prices[i - 1]; if (j % 2 == 0) { dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1] + dailyDiff); profit = Math.max(profit, dp[i][j]); } else { dp[i][j] = Math.max(dp[i - 1][j] + dailyDiff, dp[i - 1][j - 1]); } } } return profit; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = 0 ; int var_5 = var_0 . length ; int [ ] [ ] var_7 = new int [ var_5 ] [ 5 ] ; var_7 [ 0 ] [ 0 ] = 0 ; for ( int var_9 = 1 ; var_9 < var_5 ; var_9 ++ ) { for ( int var_10 = 1 ; var_10 < 5 ; var_10 ++ ) { int var_11 = var_0 [ var_9 ] - var_0 [ var_9 - 1 ] ; if ( var_10 % 2 == 0 ) { var_7 [ var_9 ] [ var_10 ] = Math . max ( var_7 [ var_9 - 1 ] [ var_10 ] , var_7 [ var_9 - 1 ] [ var_10 - 1 ] + var_11 ) ; var_4 = Math . max ( var_4 , var_7 [ var_9 ] [ var_10 ] ) ; } else { var_7 [ var_9 ] [ var_10 ] = Math . max ( var_7 [ var_9 - 1 ] [ var_10 ] + var_11 , var_7 [ var_9 - 1 ] [ var_10 - 1 ] ) ; } } } return var_4 ; }
460
<awangdev>Walls and Gates_4.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 ; }
461
<awangdev>57. Insert Interval_2.java
private int[][] convert(List<int[]> list) { int[][] rst = new int[list.size()][2]; for (int i = 0; i < list.size(); i++) { rst[i][0] = list.get(i)[0]; rst[i][1] = list.get(i)[1]; } return rst; }
private int [ ] [ ] sample_funcname ( List < int [ ] > var_1 ) { int [ ] [ ] var_4 = new int [ var_1 . size ( ) ] [ 2 ] ; for ( int var_6 = 0 ; var_6 < var_1 . size ( ) ; var_6 ++ ) { var_4 [ var_6 ] [ 0 ] = var_1 . get ( var_6 ) [ 0 ] ; var_4 [ var_6 ] [ 1 ] = var_1 . get ( var_6 ) [ 1 ] ; } return var_4 ; }
462
<awangdev>Palindrome Permutation II_1.java
public void permutateUnique(List<String> rst, String str, boolean[] visited, String s) { if (str.length() == s.length()) { rst.add(str); return; } for (int i = 0; i < s.length(); i++) { if (visited[i] || (i > 0 && !visited[i - 1] && s.charAt(i - 1) == s.charAt(i))) { continue; } visited[i] = true; permutateUnique(rst, str + s.charAt(i), visited, s); visited[i] = false; } }
public void sample_funcname ( List < String > rst , String str , boolean [ ] visited , String s ) { if ( str . length ( ) == s . length ( ) ) { rst . add ( str ) ; return ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( visited [ i ] || ( i > 0 && ! visited [ i - 1 ] && s . charAt ( i - 1 ) == s . charAt ( i ) ) ) { continue ; } visited [ i ] = true ; permutateUnique ( rst , str + s . charAt ( i ) , visited , s ) ; visited [ i ] = false ; } }
463
<awangdev>207. Course Schedule_1.java
private boolean validateInput(int numCourses, int[][] prerequisites) { return numCourses == 0 || prerequisites == null || prerequisites.length == 0 || prerequisites[0] == null || prerequisites[0].length == 0; }
private boolean var_0 ( int var_1 , int [ ] [ ] var_2 ) { return var_1 == 0 || var_2 == null || var_2 . length == 0 || var_2 [ 0 ] == null || var_2 [ 0 ] . length == 0 ; }
464
<awangdev>Reshape the Matrix_1.java
public int[][] matrixReshape(int[][] nums, int r, int c) { int totalElements = nums.length * nums[0].length; if (totalElements != r * c || totalElements % r != 0) { return nums; } final int[][] result = new int[r][c]; int newR = 0; int newC = 0; for (int i = 0; i < nums.length; i++) { for (int j = 0; j < nums[i].length; j++) { result[newR][newC] = nums[i][j]; newC++; if (newC == c) { newC = 0; newR++; } } } return result; }
public int [ ] [ ] sample_funcname ( int [ ] [ ] var_0 , int var_1 , int var_2 ) { int var_5 = var_0 . length * var_0 [ 0 ] . length ; if ( var_5 != var_1 * var_2 || var_5 % var_1 != 0 ) { return var_0 ; } final int [ ] [ ] var_6 = new int [ var_1 ] [ var_2 ] ; int var_7 = 0 ; int var_8 = 0 ; for ( int var_9 = 0 ; var_9 < var_0 . length ; var_9 ++ ) { for ( int var_10 = 0 ; var_10 < var_0 [ var_9 ] . length ; var_10 ++ ) { var_6 [ var_7 ] [ var_8 ] = var_0 [ var_9 ] [ var_10 ] ; var_8 ++ ; if ( var_8 == var_2 ) { var_8 = 0 ; var_7 ++ ; } } } return var_6 ; }
465
<awangdev>159. Longest Substring with At Most Two Distinct Characters_2.java
public int lengthOfLongestSubstringTwoDistinct(String s) { if (s == null || s.length() == 0) return 0; int n = s.length(); Map<Character, Integer> lastOccurMap = new HashMap<>(); int left = 0, right = 0, max = 0; while (right < n) { if (lastOccurMap.size() <= 2) { lastOccurMap.put(s.charAt(right), right++); } if (lastOccurMap.size() > 2) { int leftMost = right; for (int index : lastOccurMap.values()) { leftMost = Math.min(leftMost, index); } lastOccurMap.remove(s.charAt(leftMost)); left = leftMost + 1; } max = Math.max(max, right - left); } return max; }
public int sample_funcname ( String var_1 ) { if ( var_1 == null || var_1 . length ( ) == 0 ) return 0 ; int var_5 = var_1 . length ( ) ; Map < Character , Integer > var_10 = new HashMap < > ( ) ; int var_11 = 0 , var_12 = 0 , max = 0 ; while ( var_12 < var_5 ) { if ( var_10 . size ( ) <= 2 ) { var_10 . put ( var_1 . charAt ( var_12 ) , var_12 ++ ) ; } if ( var_10 . size ( ) > 2 ) { int var_18 = var_12 ; for ( int var_20 : var_10 . values ( ) ) { var_18 = Math . min ( var_18 , var_20 ) ; } var_10 . remove ( var_1 . charAt ( var_18 ) ) ; var_11 = var_18 + 1 ; } max = Math . max ( max , var_12 - var_11 ) ; } return max ; }
466
<awangdev>Permutation Sequence_1.java
public String getPermutation(int n, int k) { if (n <= 0 || k <= 0) { return ""; } StringBuffer sb = new StringBuffer(); boolean[] visited = new boolean[n]; int factorio = 1; for (int i = 1; i < n; i++) { factorio *= i; } k = k - 1; for (int i = 0; i < n; i++) { int index = k / factorio; k = k % factorio; for (int j = 0; j < n; j++) { if (!visited[j]) { if (index == 0) { visited[j] = true; sb.append((char)('0' + j + 1)); break; } else { index--; } } } if (i < n - 1) { factorio = factorio / (n - i - 1); } } return sb.toString(); }
public String var_0 ( int var_1 , int var_2 ) { if ( var_1 <= 0 || var_2 <= 0 ) { return "" ; } StringBuffer var_6 = new StringBuffer ( ) ; boolean [ ] var_8 = new boolean [ var_1 ] ; int var_10 = 1 ; for ( int var_11 = 1 ; var_11 < var_1 ; var_11 ++ ) { var_10 *= var_11 ; } var_2 = var_2 - 1 ; for ( int var_11 = 0 ; var_11 < var_1 ; var_11 ++ ) { int var_12 = var_2 / var_10 ; var_2 = var_2 % var_10 ; for ( int var_13 = 0 ; var_13 < var_1 ; var_13 ++ ) { if ( ! var_8 [ var_13 ] ) { if ( var_12 == 0 ) { var_8 [ var_13 ] = true ; var_6 . append ( ( char ) ( '0' + var_13 + 1 ) ) ; break ; } else { var_12 -- ; } } } if ( var_11 < var_1 - 1 ) { var_10 = var_10 / ( var_1 - var_11 - 1 ) ; } } return var_6 . toString ( ) ; }
467
<awangdev>Bricks Falling When Hit_2.java
private int flip(int[][] grid, Set<String> visited) { int count = 0; for (String s : visited) { String[] ss = s.split("@"); int i = Integer.parseInt(ss[0]), j = Integer.parseInt(ss[1]); if (grid[i][j] > 0) { grid[i][j] = 0; count++; } } return count; }
private int sample_funcname ( int [ ] [ ] var_0 , Set < String > var_3 ) { int var_5 = 0 ; for ( String var_6 : var_3 ) { String [ ] var_9 = var_6 . split ( "@" ) ; int var_12 = Integer . parseInt ( var_9 [ 0 ] ) , var_14 = Integer . parseInt ( var_9 [ 1 ] ) ; if ( var_0 [ var_12 ] [ var_14 ] > 0 ) { var_0 [ var_12 ] [ var_14 ] = 0 ; var_5 ++ ; } } return var_5 ; }
468
<awangdev>743. Network Delay Time_2.java
private Map<Integer, List<int[]>> buildGraph(int[][] times) { Map<Integer, List<int[]>> graph = new HashMap<>(); for (int[] record : times) { graph.putIfAbsent(record[0], new ArrayList<>()); graph.get(record[0]).add(record); } return graph; }
private Map < Integer , List < int [ ] >> var_2 ( int [ ] [ ] var_3 ) { Map < Integer , List < int [ ] >> var_6 = new HashMap < > ( ) ; for ( int [ ] var_7 : var_3 ) { var_6 . putIfAbsent ( var_7 [ 0 ] , new ArrayList < > ( ) ) ; var_6 . get ( var_7 [ 0 ] ) . add ( var_7 ) ; } return var_6 ; }
469
<awangdev>Backpack III_5.java
public int backPackIII(int[] A, int[] V, int m) { if (A == null || V == null || A.length != V.length) { return 0; } int n = A.length; int[][] dp = new int[n + 1][m + 1]; for (int j = 0; j <= m; j++) { dp[0][j] = -1; } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { dp[i][j] = dp[i - 1][j]; if (j - A[i - 1] >= 0) { dp[i][j] = Math.max(dp[i][j], dp[i][j - A[i - 1]] + V[i - 1]); } } } int rst = 0; for (int j = 0; j <= m; j++) { rst = Math.max(rst, dp[n][j]); } return rst; }
public int sample_funcname ( int [ ] var_0 , int [ ] var_1 , int var_2 ) { if ( var_0 == null || var_1 == null || var_0 . length != var_1 . length ) { return 0 ; } int var_6 = var_0 . length ; int [ ] [ ] var_8 = new int [ var_6 + 1 ] [ var_2 + 1 ] ; for ( int var_9 = 0 ; var_9 <= var_2 ; var_9 ++ ) { var_8 [ 0 ] [ var_9 ] = - 1 ; } var_8 [ 0 ] [ 0 ] = 0 ; for ( int var_10 = 1 ; var_10 <= var_6 ; var_10 ++ ) { for ( int var_9 = 0 ; var_9 <= var_2 ; var_9 ++ ) { var_8 [ var_10 ] [ var_9 ] = var_8 [ var_10 - 1 ] [ var_9 ] ; if ( var_9 - var_0 [ var_10 - 1 ] >= 0 ) { var_8 [ var_10 ] [ var_9 ] = Math . max ( var_8 [ var_10 ] [ var_9 ] , var_8 [ var_10 ] [ var_9 - var_0 [ var_10 - 1 ] ] + var_1 [ var_10 - 1 ] ) ; } } } int var_13 = 0 ; for ( int var_9 = 0 ; var_9 <= var_2 ; var_9 ++ ) { var_13 = Math . max ( var_13 , var_8 [ var_6 ] [ var_9 ] ) ; } return var_13 ; }
470
<awangdev>Cracking the Safe_1.java
public String crackSafe(int n, int k) { Set<String> set = new HashSet<>(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < n; i++) sb.append("0"); set.add(sb.toString()); for (int i = 0; i < Math.pow(k, n); i++) { String tail = sb.substring(sb.length() - n + 1); for (int j = k - 1; j >= 0; j--) { String newStr = tail + j; if (!set.contains(newStr)) { set.add(newStr); sb.append(j); break; } } } return sb.toString(); }
public String var_0 ( int var_1 , int var_2 ) { Set < String > var_6 = new HashSet < > ( ) ; StringBuffer var_8 = new StringBuffer ( ) ; for ( int var_10 = 0 ; var_10 < var_1 ; var_10 ++ ) var_8 . append ( "0" ) ; var_6 . add ( var_8 . toString ( ) ) ; for ( int var_10 = 0 ; var_10 < Math . pow ( var_2 , var_1 ) ; var_10 ++ ) { String var_20 = var_8 . substring ( var_8 . length ( ) - var_1 + 1 ) ; for ( int var_21 = var_2 - 1 ; var_21 >= 0 ; var_21 -- ) { String var_22 = var_20 + var_21 ; if ( ! var_6 . contains ( var_22 ) ) { var_6 . add ( var_22 ) ; var_8 . append ( var_21 ) ; break ; } } } return var_8 . toString ( ) ; }
471
<awangdev>Scramble String_2.java
public boolean isScramble(String s1, String s2) { if (s1 == null || s2 == null || s1.length() != s2.length()) { return false; } int n = s1.length(); boolean[][][] dp = new boolean[n][n][n + 1]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i][j][1] = s1.charAt(i) == s2.charAt(j); } } for (int len = 2; len <= n; len++) { for (int i = 0; i <= n - len; i++) { for (int j = 0; j <= n - len; j++) { for (int w = 1; w < len; w++) { dp[i][j][len] |= (dp[i][j][w] && dp[i + w][j + w][len - w]); dp[i][j][len] |= (dp[i][j + len - w][w] && dp[i + w][j][len - w]); } } } } return dp[0][0][n]; }
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 ; } int var_6 = var_2 . length ( ) ; boolean [ ] [ ] [ ] var_9 = new boolean [ var_6 ] [ var_6 ] [ var_6 + 1 ] ; for ( int var_11 = 0 ; var_11 < var_6 ; var_11 ++ ) { for ( int var_12 = 0 ; var_12 < var_6 ; var_12 ++ ) { var_9 [ var_11 ] [ var_12 ] [ 1 ] = var_2 . charAt ( var_11 ) == var_3 . charAt ( var_12 ) ; } } for ( int var_15 = 2 ; var_15 <= var_6 ; var_15 ++ ) { for ( int var_11 = 0 ; var_11 <= var_6 - var_15 ; var_11 ++ ) { for ( int var_12 = 0 ; var_12 <= var_6 - var_15 ; var_12 ++ ) { for ( int var_16 = 1 ; var_16 < var_15 ; var_16 ++ ) { var_9 [ var_11 ] [ var_12 ] [ var_15 ] |= ( var_9 [ var_11 ] [ var_12 ] [ var_16 ] && var_9 [ var_11 + var_16 ] [ var_12 + var_16 ] [ var_15 - var_16 ] ) ; var_9 [ var_11 ] [ var_12 ] [ var_15 ] |= ( var_9 [ var_11 ] [ var_12 + var_15 - var_16 ] [ var_16 ] && var_9 [ var_11 + var_16 ] [ var_12 ] [ var_15 - var_16 ] ) ; } } } } return var_9 [ 0 ] [ 0 ] [ var_6 ] ; }
472
<awangdev>76. Minimum Window Substring_2.java
public String minWindow(String s, String t) { int end = 0, start = 0, head = 0, counter = t.length(); int minLength = Integer.MAX_VALUE, n = s.length(); String rst = ""; int[] map = new int[256]; for (char c : t.toCharArray()) map[c]++; while (end < n) { if (map[s.charAt(end++)]-- > 0) counter--; while (counter == 0) { int len = end - start; if (len < minLength) { minLength = len; head = start; } if (map[s.charAt(start++)]++ == 0) counter++; } } return minLength == Integer.MAX_VALUE ? "" : s.substring(head, head + minLength); }
public String var_0 ( String var_2 , String var_3 ) { int var_5 = 0 , var_6 = 0 , var_7 = 0 , var_9 = var_3 . length ( ) ; int var_12 = Integer . MAX_VALUE , var_13 = var_2 . length ( ) ; String var_15 = "" ; int [ ] var_17 = new int [ 256 ] ; for ( char var_19 : var_3 . toCharArray ( ) ) var_17 [ var_19 ] ++ ; while ( var_5 < var_13 ) { if ( var_17 [ var_2 . charAt ( var_5 ++ ) ] -- > 0 ) var_9 -- ; while ( var_9 == 0 ) { int var_21 = var_5 - var_6 ; if ( var_21 < var_12 ) { var_12 = var_21 ; var_7 = var_6 ; } if ( var_17 [ var_2 . charAt ( var_6 ++ ) ] ++ == 0 ) var_9 ++ ; } } return var_12 == Integer . MAX_VALUE ? "" : var_2 . substring ( var_7 , var_7 + var_12 ) ; }
473
<awangdev>Kth Largest Element in an Array_3.java
public void swap( ArrayList<Integer>nums, int x, int y){ int temp = nums.get(x); nums.set(x, nums.get(y)); nums.set(y, temp); }
public void var_0 ( ArrayList < Integer > var_3 , int var_4 , int var_5 ) { int var_7 = var_3 . get ( var_4 ) ; var_3 . set ( var_4 , var_3 . get ( var_5 ) ) ; var_3 . set ( var_5 , var_7 ) ; }
474
<awangdev>Sort Colors II_1.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 ; }
475
<awangdev>151. Reverse Words in a String_2.java
private void reverse(String[] strs) { int i = 0, j = strs.length - 1; while (i < j) { String temp = strs[i]; strs[i++] = strs[j]; strs[j--] = temp; } }
private void var_0 ( String [ ] var_2 ) { int var_4 = 0 , var_7 = var_2 . length - 1 ; while ( var_4 < var_7 ) { String var_8 = var_2 [ var_4 ] ; var_2 [ var_4 ++ ] = var_2 [ var_7 ] ; var_2 [ var_7 -- ] = var_8 ; } }
476
<awangdev>210. Course Schedule II_1.java
public int[] findOrder(int numCourses, int[][] prerequisites) { if (numCourses == 0 || prerequisites == null) { return new int[numCourses]; } List[] inDegreeEdges = new ArrayList[numCourses]; int[] dependencyCount = new int[numCourses]; for (int i = 0; i < numCourses; i++) inDegreeEdges[i] = new ArrayList<>(); for (int[] prerequisite : prerequisites) { inDegreeEdges[prerequisite[1]].add(prerequisite[0]); dependencyCount[prerequisite[0]]++; } Queue<Integer> queue = new LinkedList<>(); for (int i = 0; i < numCourses; i++) { if (dependencyCount[i] == 0) queue.add(i); } List<Integer> sortedList = new ArrayList<>(); while (!queue.isEmpty()) { int leafNode = queue.poll(); sortedList.add(leafNode); List<Integer> dependencies = inDegreeEdges[leafNode]; for (int node : dependencies) { if (--dependencyCount[node] == 0) queue.add(node); } } if (sortedList.size() != numCourses) { return new int[0]; } int[] rst = new int[sortedList.size()]; for (int i = 0; i < sortedList.size(); i++) { rst[i] = sortedList.get(i); } return rst; }
public int [ ] sample_funcname ( int var_0 , int [ ] [ ] var_1 ) { if ( var_0 == 0 || var_1 == null ) { return new int [ var_0 ] ; } List [ ] var_6 = new ArrayList [ var_0 ] ; int [ ] var_7 = new int [ var_0 ] ; for ( int var_8 = 0 ; var_8 < var_0 ; var_8 ++ ) var_6 [ var_8 ] = new ArrayList < > ( ) ; for ( int [ ] var_9 : var_1 ) { var_6 [ var_9 [ 1 ] ] . add ( var_9 [ 0 ] ) ; var_7 [ var_9 [ 0 ] ] ++ ; } Queue < Integer > var_15 = new LinkedList < > ( ) ; for ( int var_8 = 0 ; var_8 < var_0 ; var_8 ++ ) { if ( var_7 [ var_8 ] == 0 ) var_15 . add ( var_8 ) ; } List < Integer > var_16 = new ArrayList < > ( ) ; while ( ! var_15 . isEmpty ( ) ) { int var_19 = var_15 . poll ( ) ; var_16 . add ( var_19 ) ; List < Integer > var_20 = var_6 [ var_19 ] ; for ( int var_21 : var_20 ) { if ( -- var_7 [ var_21 ] == 0 ) var_15 . add ( var_21 ) ; } } if ( var_16 . size ( ) != var_0 ) { return new int [ 0 ] ; } int [ ] var_23 = new int [ var_16 . size ( ) ] ; for ( int var_8 = 0 ; var_8 < var_16 . size ( ) ; var_8 ++ ) { var_23 [ var_8 ] = var_16 . get ( var_8 ) ; } return var_23 ; }
477
<awangdev>611. Valid Triangle Number_2.java
public int triangleNumber(int[] nums) { Arrays.sort(nums); int n = nums.length, count = 0; for (int i = 0; i <= n - 3; i++) { if (nums[i] == 0) continue; int k = i + 2; for (int j = i + 1; j <= n - 2; j++) { while (k < n && nums[i] + nums[j] > nums[k]) k++; count += k - j - 1; } } return count; }
public int sample_funcname ( int [ ] var_0 ) { Arrays . sort ( var_0 ) ; int var_4 = var_0 . length , var_6 = 0 ; for ( int var_7 = 0 ; var_7 <= var_4 - 3 ; var_7 ++ ) { if ( var_0 [ var_7 ] == 0 ) continue ; int var_10 = var_7 + 2 ; for ( int var_12 = var_7 + 1 ; var_12 <= var_4 - 2 ; var_12 ++ ) { while ( var_10 < var_4 && var_0 [ var_7 ] + var_0 [ var_12 ] > var_0 [ var_10 ] ) var_10 ++ ; var_6 += var_10 - var_12 - 1 ; } } return var_6 ; }
478
<awangdev>217. Contains Duplicate_2.java
public boolean containsDuplicate(int[] nums) { if (nums == null || nums.length == 0) { return false; } Arrays.sort(nums); for (int i = 0; i < nums.length - 1; i++) { if (nums[i] == nums[i + 1]) { return true; } } return false; }
public boolean var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 ) { return false ; } Arrays . sort ( var_1 ) ; for ( int var_7 = 0 ; var_7 < var_1 . length - 1 ; var_7 ++ ) { if ( var_1 [ var_7 ] == var_1 [ var_7 + 1 ] ) { return true ; } } return false ; }
479
<awangdev>246. Strobogrammatic Number_2.java
public boolean isStrobogrammatic(String num) { if (num == null || num.length() == 0) return true; if (num.length() == 1) return num.equals("0") || num.equals("1") || num.equals("8"); List<Character> candidate = new ArrayList<>(Arrays.asList('0', '1', '8', '6', '9')); char[] charArray = num.toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!candidate.contains(charArray[i])) return false; if (charArray[i] == '6') charArray[i] = '9'; else if (charArray[i] == '9') charArray[i] = '6'; } StringBuffer sb = new StringBuffer(String.valueOf(charArray)); String reversedNum = sb.reverse().toString(); return num.equals(reversedNum); }
public boolean var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) return true ; if ( var_2 . length ( ) == 1 ) return var_2 . equals ( "0" ) || var_2 . equals ( "1" ) || var_2 . equals ( "8" ) ; List < Character > var_21 = new ArrayList < > ( Arrays . asList ( '0' , '1' , '8' , '6' , '9' ) ) ; char [ ] var_23 = var_2 . toCharArray ( ) ; for ( int var_24 = 0 ; var_24 < var_23 . length ; var_24 ++ ) { if ( ! var_21 . contains ( var_23 [ var_24 ] ) ) return false ; if ( var_23 [ var_24 ] == '6' ) var_23 [ var_24 ] = '9' ; else if ( var_23 [ var_24 ] == '9' ) var_23 [ var_24 ] = '6' ; } StringBuffer var_28 = new StringBuffer ( String . valueOf ( var_23 ) ) ; String var_31 = var_28 . reverse ( ) . toString ( ) ; return var_2 . equals ( var_31 ) ; }
480
<awangdev>Container With Most Water_1.java
public int maxArea(int[] heights) { if (heights == null || heights.length == 0) { return 0; } int left = 0; int right = heights.length - 1; int maxWater = Integer.MIN_VALUE; while (left < right) { int lowWall = heights[left] < heights[right] ? heights[left] : heights[right]; maxWater = Math.max(maxWater, (right - left) * lowWall); if (heights[left] < heights[right]) { left++; } else { right--; } } return maxWater; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = 0 ; int var_6 = var_0 . length - 1 ; int var_9 = Integer . MIN_VALUE ; while ( var_4 < var_6 ) { int var_10 = var_0 [ var_4 ] < var_0 [ var_6 ] ? var_0 [ var_4 ] : var_0 [ var_6 ] ; var_9 = Math . max ( var_9 , ( var_6 - var_4 ) * var_10 ) ; if ( var_0 [ var_4 ] < var_0 [ var_6 ] ) { var_4 ++ ; } else { var_6 -- ; } } return var_9 ; }
481
<awangdev>Max Area of Island_1.java
private boolean validate(int[][] 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 ( int [ ] [ ] 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 ; }
482
<awangdev>Sliding Puzzle_2.java
private boolean evaluate(int[] nums) { for (int i = 0; i < nums.length; i++) { if (i + 1 != nums[i]) { if (i == 5 && nums[i] == 0) continue; return false; } } return true; }
private boolean var_0 ( int [ ] var_1 ) { for ( int var_3 = 0 ; var_3 < var_1 . length ; var_3 ++ ) { if ( var_3 + 1 != var_1 [ var_3 ] ) { if ( var_3 == 5 && var_1 [ var_3 ] == 0 ) continue ; return false ; } } return true ; }
483
<awangdev>58. Length of Last Word_2.java
public int lengthOfLastWord(String s) { if (s == null || s.length() == 0) { return 0; } String[] arr = s.split("\\ "); String lastWord = arr[arr.length - 1]; return lastWord.length(); }
public int sample_funcname ( String var_1 ) { if ( var_1 == null || var_1 . length ( ) == 0 ) { return 0 ; } String [ ] var_7 = var_1 . split ( "\\ " ) ; String var_9 = var_7 [ var_7 . length - 1 ] ; return var_9 . length ( ) ; }
484
<awangdev>686. Repeated String Match_1.java
private boolean validate(String A, String B) { boolean[] checkA = new boolean[256]; boolean[] checkB = new boolean[256]; for (char c : A.toCharArray()) { checkA[c] = true; } for (char c : B.toCharArray()) { checkB[c] = true; } for (int i = 0; i < 256; i++) { if (checkB[i] && !checkA[i]) { return false; } } return true; }
private boolean var_0 ( String var_2 , String var_3 ) { boolean [ ] var_6 = new boolean [ 256 ] ; boolean [ ] var_7 = new boolean [ 256 ] ; for ( char var_9 : var_2 . toCharArray ( ) ) { var_6 [ var_9 ] = true ; } for ( char var_9 : var_3 . toCharArray ( ) ) { var_7 [ var_9 ] = true ; } for ( int var_11 = 0 ; var_11 < 256 ; var_11 ++ ) { if ( var_7 [ var_11 ] && ! var_6 [ var_11 ] ) { return false ; } } return true ; }
485
<awangdev>Perfect Squares_4.java
public int numSquares(int n) { if (n <= 0) { return 0; } int[] dp = new int[n + 1]; dp[0] = 0; for (int i = 1; i <= n; i++) { int maxSqrNum = (int)Math.floor(Math.sqrt(i)); int min = Integer.MAX_VALUE; for (int j = 1; j <= maxSqrNum; j++) { min = Math.min(min, dp[i - j * j] + 1); } dp[i] = min; } return dp[n]; }
public int sample_funcname ( int var_0 ) { if ( var_0 <= 0 ) { return 0 ; } int [ ] var_3 = new int [ var_0 + 1 ] ; var_3 [ 0 ] = 0 ; for ( int var_4 = 1 ; var_4 <= var_0 ; var_4 ++ ) { int var_8 = ( int ) Math . floor ( Math . sqrt ( var_4 ) ) ; int min = Integer . MAX_VALUE ; for ( int var_12 = 1 ; var_12 <= var_8 ; var_12 ++ ) { min = Math . min ( min , var_3 [ var_4 - var_12 * var_12 ] + 1 ) ; } var_3 [ var_4 ] = min ; } return var_3 [ var_0 ] ; }
486
<awangdev>408. Valid Word Abbreviation_1.java
private boolean isInt(char c) { return c >= '0' && c <= '9'; }
private boolean var_0 ( char var_1 ) { return var_1 >= '0' && var_1 <= '9' ; }
487
<awangdev>Word Search II_2.java
public boolean search(char[][] board, String word, int i, int j, int start) { if (start == word.length()) { return true; } if (i < 0 || i >= board.length || j < 0 || j >= board[0].length || board[i][j] != word.charAt(start)) { return false; } board[i][j] = '#'; boolean rst = search(board, word, i, j - 1, start + 1) || search(board, word, i, j + 1, start + 1) || search(board, word, i + 1, j, start + 1) || search(board, word, i - 1, j, start + 1); board[i][j] = word.charAt(start); return rst; }
public boolean sample_funcname ( char [ ] [ ] board , String word , int i , int j , int start ) { if ( start == word . length ( ) ) { return true ; } if ( i < 0 || i >= board . length || j < 0 || j >= board [ 0 ] . length || board [ i ] [ j ] != word . charAt ( start ) ) { return false ; } board [ i ] [ j ] = '#' ; boolean rst = search ( board , word , i , j - 1 , start + 1 ) || search ( board , word , i , j + 1 , start + 1 ) || search ( board , word , i + 1 , j , start + 1 ) || search ( board , word , i - 1 , j , start + 1 ) ; board [ i ] [ j ] = word . charAt ( start ) ; return rst ; }
488
<awangdev>Backpack_3.java
public int backPack(int m, int[] A) { if (A == null || A.length < 0) { return 0; } int n = A.length; boolean[][] dp = new boolean[n + 1][m + 1]; dp[0][0] = true; for (int j = 1; j <= m; j++) { dp[0][j] = false; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { dp[i][j] = dp[i - 1][j]; if (j - A[i - 1] >= 0) { dp[i][j] |= dp[i - 1][j - A[i - 1]]; } } } for (int j = m; j >= 0; j--) { if (dp[n][j]) { return j; } } return 0; }
public int sample_funcname ( int var_0 , int [ ] var_1 ) { if ( var_1 == null || var_1 . length < 0 ) { return 0 ; } int var_5 = var_1 . length ; boolean [ ] [ ] var_8 = new boolean [ var_5 + 1 ] [ var_0 + 1 ] ; var_8 [ 0 ] [ 0 ] = true ; for ( int var_9 = 1 ; var_9 <= var_0 ; var_9 ++ ) { var_8 [ 0 ] [ var_9 ] = false ; } for ( int var_10 = 1 ; var_10 <= var_5 ; var_10 ++ ) { for ( int var_9 = 0 ; var_9 <= var_0 ; var_9 ++ ) { var_8 [ var_10 ] [ var_9 ] = var_8 [ var_10 - 1 ] [ var_9 ] ; if ( var_9 - var_1 [ var_10 - 1 ] >= 0 ) { var_8 [ var_10 ] [ var_9 ] |= var_8 [ var_10 - 1 ] [ var_9 - var_1 [ var_10 - 1 ] ] ; } } } for ( int var_9 = var_0 ; var_9 >= 0 ; var_9 -- ) { if ( var_8 [ var_5 ] [ var_9 ] ) { return var_9 ; } } return 0 ; }
489
<awangdev>1041. Robot Bounded In Circle_1.java
public boolean judgeCircle(String moves) { if (moves == null || moves.length() % 2 == 1) { return false; } int trackX = 0; int trackY = 0; for (int i = 0; i < moves.length(); i++) { if (moves.charAt(i) == 'U' || moves.charAt(i) == 'D') { trackY += moves.charAt(i) == 'U' ? 1 : -1; } if (moves.charAt(i) == 'L' || moves.charAt(i) == 'R') { trackX += moves.charAt(i) == 'L' ? 1 : -1; } } return trackX == 0 && trackY == 0; }
public boolean var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) % 2 == 1 ) { return false ; } int var_8 = 0 ; int var_9 = 0 ; for ( int var_10 = 0 ; var_10 < var_2 . length ( ) ; var_10 ++ ) { if ( var_2 . charAt ( var_10 ) == 'U' || var_2 . charAt ( var_10 ) == 'D' ) { var_9 += var_2 . charAt ( var_10 ) == 'U' ? 1 : - 1 ; } if ( var_2 . charAt ( var_10 ) == 'L' || var_2 . charAt ( var_10 ) == 'R' ) { var_8 += var_2 . charAt ( var_10 ) == 'L' ? 1 : - 1 ; } } return var_8 == 0 && var_9 == 0 ; }
490
<awangdev>Largest Rectangle in Histogram_1.java
public int largestRectangleArea(int[] heights) { if (heights == null || heights.length == 0) { return 0; } int n = heights.length; int max = 0; Stack<Integer> stack = new Stack<>(); for (int i = 0; i <= n; i++) { int currHeight = i == n ? -1 : heights[i]; while (!stack.isEmpty() && currHeight <= heights[stack.peek()]) { int currPeekHeight = heights[stack.pop()]; int width = stack.isEmpty() ? i : i - stack.peek() - 1; max = Math.max(max, currPeekHeight * width); } stack.push(i); } 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 max = 0 ; Stack < Integer > var_8 = new Stack < > ( ) ; for ( int var_9 = 0 ; var_9 <= var_4 ; var_9 ++ ) { int var_11 = var_9 == var_4 ? - 1 : var_0 [ var_9 ] ; while ( ! var_8 . isEmpty ( ) && var_11 <= var_0 [ var_8 . peek ( ) ] ) { int var_15 = var_0 [ var_8 . pop ( ) ] ; int var_16 = var_8 . isEmpty ( ) ? var_9 : var_9 - var_8 . peek ( ) - 1 ; max = Math . max ( max , var_15 * var_16 ) ; } var_8 . push ( var_9 ) ; } return max ; }
491
<awangdev>399. Evaluate Division_1.java
private String getKey(String a, String b) { return String.format("%s->%s", a, b); }
private String var_0 ( String var_2 , String var_3 ) { return String . format ( "%s->%s" , var_2 , var_3 ) ; }
492
<awangdev>64. Minimum Path Sum_3.java
public int minPathSum(int[][] grid) { if (grid == null || grid.length == 0 || grid[0] == null || grid[0].length == 0) return 0; int m = grid.length, n = grid[0].length; int[][] dp = new int[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { dp[i][j] = grid[i][j]; if (i == 0 && j == 0) continue; if (i == 0 && j > 0) dp[i][j] += dp[i][j - 1]; else if (i > 0 && j == 0) dp[i][j] += dp[i - 1][j]; else dp[i][j] += Math.min(dp[i - 1][j], dp[i][j - 1]); } } return dp[m - 1][n - 1]; }
public int sample_funcname ( int [ ] [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 || var_0 [ 0 ] == null || var_0 [ 0 ] . length == 0 ) return 0 ; int var_4 = var_0 . length , var_5 = var_0 [ 0 ] . length ; int [ ] [ ] var_6 = new int [ var_4 ] [ var_5 ] ; for ( int var_7 = 0 ; var_7 < var_4 ; var_7 ++ ) { for ( int var_8 = 0 ; var_8 < var_5 ; var_8 ++ ) { var_6 [ var_7 ] [ var_8 ] = var_0 [ var_7 ] [ var_8 ] ; if ( var_7 == 0 && var_8 == 0 ) continue ; if ( var_7 == 0 && var_8 > 0 ) var_6 [ var_7 ] [ var_8 ] += var_6 [ var_7 ] [ var_8 - 1 ] ; else if ( var_7 > 0 && var_8 == 0 ) var_6 [ var_7 ] [ var_8 ] += var_6 [ var_7 - 1 ] [ var_8 ] ; else var_6 [ var_7 ] [ var_8 ] += Math . min ( var_6 [ var_7 - 1 ] [ var_8 ] , var_6 [ var_7 ] [ var_8 - 1 ] ) ; } } return var_6 [ var_4 - 1 ] [ var_5 - 1 ] ; }
493
<awangdev>311. Sparse Matrix Multiplication_1.java
private boolean validate(int[][] A, int[][] B) { if (A == null || B == null) return true; if (A[0].length != B.length) return true; return false; }
private boolean var_0 ( int [ ] [ ] var_1 , int [ ] [ ] var_2 ) { if ( var_1 == null || var_2 == null ) return true ; if ( var_1 [ 0 ] . length != var_2 . length ) return true ; return false ; }
494
<awangdev>327. Count of Range Sum_1.java
private int mergeSort(long[] preSum, int lower, int upper, int start, int end) { if (start + 1 >= end) return 0; int mid = (start + end) / 2, count = 0; count += mergeSort(preSum, lower, upper, start, mid); count += mergeSort(preSum, lower, upper, mid, end); int lo = mid, hi = mid; for (int i = start; i < mid; i++) { while (lo < end && preSum[lo] - preSum[i] < lower) lo++; while (hi < end && preSum[hi] - preSum[i] <= upper) hi++; count += hi - lo; } Arrays.sort(preSum, start, end); return count; }
private int sample_funcname ( long [ ] preSum , int lower , int upper , int start , int end ) { if ( start + 1 >= end ) return 0 ; int mid = ( start + end ) / 2 , count = 0 ; count += mergeSort ( preSum , lower , upper , start , mid ) ; count += mergeSort ( preSum , lower , upper , mid , end ) ; int lo = mid , hi = mid ; for ( int i = start ; i < mid ; i ++ ) { while ( lo < end && preSum [ lo ] - preSum [ i ] < lower ) lo ++ ; while ( hi < end && preSum [ hi ] - preSum [ i ] <= upper ) hi ++ ; count += hi - lo ; } Arrays . sort ( preSum , start , end ) ; return count ; }
495
<awangdev>Find Peak Element_4.java
public int findPeak(int[] A) { int start = 1; int end = A.length - 2; int mid; while (start + 1 < end) { mid = start + (end - start) / 2; if (A[mid] > A[mid - 1] && A[mid] > A[mid + 1]) { return mid; } else if (A[mid] > A[start] && A[mid] < A[mid + 1]) { start = mid; } else { end = mid; } } if (A[start] > A[start - 1] && A[start] > A[start + 1]) { return start; } else { return end; } }
public int sample_funcname ( int [ ] var_0 ) { int var_2 = 1 ; int var_5 = var_0 . length - 2 ; int var_6 ; while ( var_2 + 1 < var_5 ) { var_6 = var_2 + ( var_5 - var_2 ) / 2 ; if ( var_0 [ var_6 ] > var_0 [ var_6 - 1 ] && var_0 [ var_6 ] > var_0 [ var_6 + 1 ] ) { return var_6 ; } else if ( var_0 [ var_6 ] > var_0 [ var_2 ] && var_0 [ var_6 ] < var_0 [ var_6 + 1 ] ) { var_2 = var_6 ; } else { var_5 = var_6 ; } } if ( var_0 [ var_2 ] > var_0 [ var_2 - 1 ] && var_0 [ var_2 ] > var_0 [ var_2 + 1 ] ) { return var_2 ; } else { return var_5 ; } }
496
<awangdev>567. Permutation in String_1.java
private Integer[] countFreq(String s) { Integer[] freq = new Integer[256]; for (char c : s.toCharArray()) freq[c] = freq[c] == null ? 1 : freq[c] + 1; return freq; }
private Integer [ ] var_0 ( String var_2 ) { Integer [ ] var_5 = new Integer [ 256 ] ; for ( char var_7 : var_2 . toCharArray ( ) ) var_5 [ var_7 ] = var_5 [ var_7 ] == null ? 1 : var_5 [ var_7 ] + 1 ; return var_5 ; }
497
<awangdev>Expression Evaluation_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 ; }
498
<awangdev>10. Regular Expression Matching_1.java
public boolean isMatch(String s, String p) { if (s == null || p == null) return false; int m = s.length(), n = p.length(); boolean[][] dp = new boolean[m + 1][n + 1]; char[] ss = s.toCharArray(); char[] pp = p.toCharArray(); for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0 && j == 0) { dp[i][j] = true; continue; } if (j == 0) { dp[i][j] = false; continue; } dp[i][j] = false; if (pp[j - 1] != '*') { if (i >= 1 && (ss[i - 1] == pp[j - 1] || pp[j - 1] == '.')) { dp[i][j] = dp[i - 1][j - 1]; } } else { if (j >= 2 ) { dp[i][j] |= dp[i][j - 2]; } if (j >= 2 && i >= 1 && (ss[i - 1] == pp[j - 2] || pp[j - 2] == '.')) { dp[i][j] |= dp[i - 1][j]; } } } } return dp[m][n]; }
public boolean var_0 ( String var_2 , String var_3 ) { if ( var_2 == null || var_3 == null ) return false ; int var_6 = var_2 . length ( ) , var_7 = var_3 . length ( ) ; boolean [ ] [ ] var_10 = new boolean [ var_6 + 1 ] [ var_7 + 1 ] ; char [ ] var_12 = var_2 . toCharArray ( ) ; char [ ] var_13 = var_3 . toCharArray ( ) ; for ( int var_15 = 0 ; var_15 <= var_6 ; var_15 ++ ) { for ( int var_16 = 0 ; var_16 <= var_7 ; var_16 ++ ) { if ( var_15 == 0 && var_16 == 0 ) { var_10 [ var_15 ] [ var_16 ] = true ; continue ; } if ( var_16 == 0 ) { var_10 [ var_15 ] [ var_16 ] = false ; continue ; } var_10 [ var_15 ] [ var_16 ] = false ; if ( var_13 [ var_16 - 1 ] != '*' ) { if ( var_15 >= 1 && ( var_12 [ var_15 - 1 ] == var_13 [ var_16 - 1 ] || var_13 [ var_16 - 1 ] == '.' ) ) { var_10 [ var_15 ] [ var_16 ] = var_10 [ var_15 - 1 ] [ var_16 - 1 ] ; } } else { if ( var_16 >= 2 ) { var_10 [ var_15 ] [ var_16 ] |= var_10 [ var_15 ] [ var_16 - 2 ] ; } if ( var_16 >= 2 && var_15 >= 1 && ( var_12 [ var_15 - 1 ] == var_13 [ var_16 - 2 ] || var_13 [ var_16 - 2 ] == '.' ) ) { var_10 [ var_15 ] [ var_16 ] |= var_10 [ var_15 - 1 ] [ var_16 ] ; } } } } return var_10 [ var_6 ] [ var_7 ] ; }
499
<awangdev>91. Decode Ways_3.java
private boolean check(String s, int i) { if (i + 1 >= s.length()) return false; int twoDigit = (s.charAt(i) - '0') * 10 + (s.charAt(i + 1) - '0'); return twoDigit <= 26 && twoDigit >= 10; }
private boolean var_0 ( String var_2 , int var_3 ) { if ( var_3 + 1 >= var_2 . length ( ) ) return false ; int var_9 = ( var_2 . charAt ( var_3 ) - '0' ) * 10 + ( var_2 . charAt ( var_3 + 1 ) - '0' ) ; return var_9 <= 26 && var_9 >= 10 ; }