id
int64
0
1.17k
comefrom
stringlengths
21
84
code
stringlengths
50
1.89k
masked
stringlengths
63
2.47k
500
<awangdev>200. Number of Islands_3.java
private int convertToIndex(int x, int y, int rowLength) { return x * rowLength + y; }
private int sample_funcname ( int var_0 , int var_1 , int var_2 ) { return var_0 * var_2 + var_1 ; }
501
<awangdev>46. Permutations_6.java
public List<List<Integer>> permute(int[] nums) { List<List<Integer>> rst = new ArrayList<>(); if (nums == null || nums.length == 0) return rst; List<Integer> numList = new ArrayList<>(); for (int num : nums) numList.add(num); int n = nums.length; Queue<List<Integer>> queue = new LinkedList<>(); queue.offer(new ArrayList<>()); while (!queue.isEmpty()) { List<Integer> list = queue.poll(); if (list.size() == n) { rst.add(new ArrayList<>(list)); continue; } List<Integer> candidates = new ArrayList<>(numList); candidates.removeAll(list); for (int num : candidates) { list.add(num); queue.offer(new ArrayList<>(list)); list.remove(list.size() - 1); } } return rst; }
public List < List < Integer >> var_2 ( int [ ] var_3 ) { List < List < Integer >> var_5 = new ArrayList < > ( ) ; if ( var_3 == null || var_3 . length == 0 ) return var_5 ; List < Integer > var_9 = new ArrayList < > ( ) ; for ( int var_10 : var_3 ) var_9 . add ( var_10 ) ; int var_12 = var_3 . length ; Queue < List < Integer >> var_15 = new LinkedList < > ( ) ; var_15 . offer ( new ArrayList < > ( ) ) ; while ( ! var_15 . isEmpty ( ) ) { List < Integer > var_19 = var_15 . poll ( ) ; if ( var_19 . size ( ) == var_12 ) { var_5 . add ( new ArrayList < > ( var_19 ) ) ; continue ; } List < Integer > var_21 = new ArrayList < > ( var_9 ) ; var_21 . removeAll ( var_19 ) ; for ( int var_10 : var_21 ) { var_19 . add ( var_10 ) ; var_15 . offer ( new ArrayList < > ( var_19 ) ) ; var_19 . remove ( var_19 . size ( ) - 1 ) ; } } return var_5 ; }
502
<awangdev>53. Maximum Subarray_7.java
private int findContinuousSum(int start, int left, int right, int offset, int[] nums) { int continuousSum = 0, max = 0; for (int i = start; i >= left && i <= right; i+=offset) { continuousSum += nums[i]; max = Math.max(max, continuousSum); } return max; }
private int sample_funcname ( int var_0 , int var_1 , int var_2 , int var_3 , int [ ] var_4 ) { int var_6 = 0 , max = 0 ; for ( int var_8 = var_0 ; var_8 >= var_1 && var_8 <= var_2 ; var_8 += var_3 ) { var_6 += var_4 [ var_8 ] ; max = Math . max ( max , var_6 ) ; } return max ; }
503
<awangdev>Longest Consecutive Sequence_3.java
public int longestConsecutive(int[] num) { if (num == null || num.length == 0) { return 0; } if (num.length == 1) { return 1; } int count = 1; int max = 1; Arrays.sort(num); for (int i = 1; i < num.length; i++) { if (num[i - 1] == num[i]) { continue; } else if (num[i - 1] + 1 == num[i]) { count++; max = Math.max(count, max); } else { count = 1; } } return max; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } if ( var_0 . length == 1 ) { return 1 ; } int var_5 = 1 ; int max = 1 ; Arrays . sort ( var_0 ) ; for ( int var_9 = 1 ; var_9 < var_0 . length ; var_9 ++ ) { if ( var_0 [ var_9 - 1 ] == var_0 [ var_9 ] ) { continue ; } else if ( var_0 [ var_9 - 1 ] + 1 == var_0 [ var_9 ] ) { var_5 ++ ; max = Math . max ( var_5 , max ) ; } else { var_5 = 1 ; } } return max ; }
504
<awangdev>767. Reorganize String_1.java
public String reorganizeString(String S) { if (S == null || S.length() == 0) return ""; Map<Character, Integer> map = new HashMap<>(); for (char c : S.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } PriorityQueue<Map.Entry<Character, Integer>> pq = new PriorityQueue<>((a, b) -> (b.getValue() - a.getValue())); pq.addAll(map.entrySet()); StringBuilder sb = new StringBuilder(); Queue<Map.Entry<Character, Integer>> buffer = new LinkedList<>(); while (!pq.isEmpty()) { Map.Entry<Character, Integer> entry = pq.poll(); sb.append(entry.getKey()); entry.setValue(entry.getValue() - 1); buffer.offer(entry); if (buffer.size() == 2) { Map.Entry<Character, Integer> temp = buffer.poll(); if (temp.getValue() > 0) pq.offer(temp); } } return sb.length() == S.length() ? sb.toString() : ""; }
public String var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) return "" ; Map < Character , Integer > var_11 = new HashMap < > ( ) ; for ( char var_13 : var_2 . toCharArray ( ) ) { var_11 . put ( var_13 , var_11 . getOrDefault ( var_13 , 0 ) + 1 ) ; } PriorityQueue < Map . Entry < Character , Integer >> var_22 = new PriorityQueue < > ( ( var_20 , var_19 ) -> ( var_19 . getValue ( ) - var_20 . getValue ( ) ) ) ; var_22 . addAll ( var_11 . entrySet ( ) ) ; StringBuilder var_26 = new StringBuilder ( ) ; Queue < Map . Entry < Character , Integer >> var_29 = new LinkedList < > ( ) ; while ( ! var_22 . isEmpty ( ) ) { Map . Entry < Character , Integer > var_32 = var_22 . poll ( ) ; var_26 . append ( var_32 . getKey ( ) ) ; var_32 . setValue ( var_32 . getValue ( ) - 1 ) ; var_29 . offer ( var_32 ) ; if ( var_29 . size ( ) == 2 ) { Map . Entry < Character , Integer > var_39 = var_29 . poll ( ) ; if ( var_39 . getValue ( ) > 0 ) var_22 . offer ( var_39 ) ; } } return var_26 . length ( ) == var_2 . length ( ) ? var_26 . toString ( ) : "" ; }
505
<awangdev>349. Intersection of Two Arrays_2.java
private boolean binarySearch(int[] nums, int target) { int start = 0; int end = nums.length - 1; while(start <= end) { int mid = (start + end) / 2; if (nums[mid] < target) { start = mid + 1; } else if (nums[mid] > target) { end = mid - 1; } else { return true; } } return false; }
private boolean var_0 ( int [ ] var_1 , int var_2 ) { int var_4 = 0 ; int var_7 = var_1 . length - 1 ; while ( var_4 <= var_7 ) { int var_9 = ( var_4 + var_7 ) / 2 ; if ( var_1 [ var_9 ] < var_2 ) { var_4 = var_9 + 1 ; } else if ( var_1 [ var_9 ] > var_2 ) { var_7 = var_9 - 1 ; } else { return true ; } } return false ; }
506
<awangdev>680. Valid Palindrome II_2.java
public boolean validate(String s, int start, int end, boolean state) { if (start > end) return false; while (start < end) { if (s.charAt(start++) == s.charAt(end--)) { continue; } else if (state) { return validate(s, start - 1, end, false) || validate(s, start, end + 1, false); } return false; } return true; }
public boolean sample_funcname ( String s , int start , int end , boolean state ) { if ( start > end ) return false ; while ( start < end ) { if ( s . charAt ( start ++ ) == s . charAt ( end -- ) ) { continue ; } else if ( state ) { return validate ( s , start - 1 , end , false ) || validate ( s , start , end + 1 , false ) ; } return false ; } return true ; }
507
<awangdev>605. Can Place Flowers_1.java
public boolean canPlaceFlowers(int[] flowerbed, int n) { if (flowerbed.length == 0 || n <= 0) return true; int m = flowerbed.length; for (int i = 0; i < m; i++) { if (flowerbed[i] == 1) continue; int lastVal = i == 0 ? 0 : flowerbed[i-1]; int nextval = i == m-1? 0: flowerbed[i+1]; if (lastVal == 0 && nextval == 0) { flowerbed[i] = 1; n--; } if (n <= 0) return true; } return false; }
public boolean var_0 ( int [ ] var_1 , int var_2 ) { if ( var_1 . length == 0 || var_2 <= 0 ) return true ; int var_5 = var_1 . length ; for ( int var_6 = 0 ; var_6 < var_5 ; var_6 ++ ) { if ( var_1 [ var_6 ] == 1 ) continue ; int var_8 = var_6 == 0 ? 0 : var_1 [ var_6 - 1 ] ; int var_9 = var_6 == var_5 - 1 ? 0 : var_1 [ var_6 + 1 ] ; if ( var_8 == 0 && var_9 == 0 ) { var_1 [ var_6 ] = 1 ; var_2 -- ; } if ( var_2 <= 0 ) return true ; } return false ; }
508
<awangdev>493. Reverse Pairs_1.java
private int mergeSort(int[] nums, int start, int end) { if (start >= end) return 0; int mid = start + (end - start) / 2; int count = mergeSort(nums, start, mid) + mergeSort(nums, mid + 1, end); for (int i = start, j = mid + 1; i <= mid; i++) { while (j <= end && nums[i] / 2.0 > nums[j]) j++; count += j - (mid + 1); } Arrays.sort(nums, start, end + 1); return count; }
private int sample_funcname ( int [ ] nums , int start , int end ) { if ( start >= end ) return 0 ; int mid = start + ( end - start ) / 2 ; int count = mergeSort ( nums , start , mid ) + mergeSort ( nums , mid + 1 , end ) ; for ( int i = start , j = mid + 1 ; i <= mid ; i ++ ) { while ( j <= end && nums [ i ] / 2.0 > nums [ j ] ) j ++ ; count += j - ( mid + 1 ) ; } Arrays . sort ( nums , start , end + 1 ) ; return count ; }
509
<awangdev>Missing Number_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 ; }
510
<awangdev>Trailing Zeros_1.java
public long trailingZeros(long n) { if ( n < 5) { return 0; } long count = 0; for (long i = 5; n / i != 0; i *= 5) { count += n / i; } return count; }
public long sample_funcname ( long var_0 ) { if ( var_0 < 5 ) { return 0 ; } long var_3 = 0 ; for ( long var_4 = 5 ; var_0 / var_4 != 0 ; var_4 *= 5 ) { var_3 += var_0 / var_4 ; } return var_3 ; }
511
<awangdev>Russian Doll Envelopes_2.java
public int maxEnvelopes(int[][] envelopes) { if (envelopes == null || envelopes.length == 0 || envelopes[0] == null || envelopes[0].length == 0) { return 0; } int n = 0, m = 0; for (int[] envelope : envelopes) { n = Math.max(n, envelope[0]); m = Math.max(m, envelope[1]); } int[][] dp = new int[n + 1][m + 1]; for (int[] envelope : envelopes) { dp[envelope[0]][envelope[1]] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int temp = dp[i][j] == 1 ? dp[i - 1][j - 1] + dp[i][j] : Math.max(dp[i - 1][j], dp[i][j - 1]); dp[i][j] = Math.max(temp, dp[i][j]); } } return dp[n][m]; }
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 = 0 , var_5 = 0 ; for ( int [ ] var_6 : var_0 ) { var_4 = Math . max ( var_4 , var_6 [ 0 ] ) ; var_5 = Math . max ( var_5 , var_6 [ 1 ] ) ; } int [ ] [ ] var_10 = new int [ var_4 + 1 ] [ var_5 + 1 ] ; for ( int [ ] var_6 : var_0 ) { var_10 [ var_6 [ 0 ] ] [ var_6 [ 1 ] ] = 1 ; } for ( int var_11 = 1 ; var_11 <= var_4 ; var_11 ++ ) { for ( int var_12 = 1 ; var_12 <= var_5 ; var_12 ++ ) { int var_13 = var_10 [ var_11 ] [ var_12 ] == 1 ? var_10 [ var_11 - 1 ] [ var_12 - 1 ] + var_10 [ var_11 ] [ var_12 ] : Math . max ( var_10 [ var_11 - 1 ] [ var_12 ] , var_10 [ var_11 ] [ var_12 - 1 ] ) ; var_10 [ var_11 ] [ var_12 ] = Math . max ( var_13 , var_10 [ var_11 ] [ var_12 ] ) ; } } return var_10 [ var_4 ] [ var_5 ] ; }
512
<awangdev>977. Squares of a Sorted Array_1.java
public int findPos(int[] A) { for (int i = 0; i < A.length; i++) { if (A[i] >= 0) return i - 1; } return 0; }
public int sample_funcname ( int [ ] var_0 ) { for ( int var_2 = 0 ; var_2 < var_0 . length ; var_2 ++ ) { if ( var_0 [ var_2 ] >= 0 ) return var_2 - 1 ; } return 0 ; }
513
<awangdev>1153. String Transforms Into Another String_1.java
public boolean canConvert(String str1, String str2) { if (str1.equals(str2)) return true; Map<Character, Character> map = new HashMap<>(); for (int i = 0; i < str1.length(); i++) { char a = str1.charAt(i), b = str2.charAt(i); map.putIfAbsent(a, b); if (map.get(a) != b) return false; } return new HashSet<>(map.values()).size() < 26; }
public boolean var_0 ( String var_2 , String var_3 ) { if ( var_2 . equals ( var_3 ) ) return true ; Map < Character , Character > var_8 = new HashMap < > ( ) ; for ( int var_10 = 0 ; var_10 < var_2 . length ( ) ; var_10 ++ ) { char var_13 = var_2 . charAt ( var_10 ) , var_14 = var_3 . charAt ( var_10 ) ; var_8 . putIfAbsent ( var_13 , var_14 ) ; if ( var_8 . get ( var_13 ) != var_14 ) return false ; } return new HashSet < > ( var_8 . values ( ) ) . size ( ) < 26 ; }
514
<awangdev>Sort Colors_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 ; }
515
<awangdev>221. Maximal Square_2.java
public int maximalSquare(char[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0] == null || matrix[0].length == 0) { return 0; } int m = matrix.length; int n = matrix[0].length; int[][] dp = new int[m][n]; int maxLen = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { dp[i][j] = matrix[i][j] == '1' ? 1 : 0; maxLen = Math.max(dp[i][j], maxLen); } } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { if (matrix[i][j] == '1') { dp[i][j] = Math.min(Math.min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1; maxLen = Math.max(dp[i][j], maxLen); } } } return maxLen * maxLen; }
public int sample_funcname ( char [ ] [ ] 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 = 0 ; for ( int var_8 = 0 ; var_8 < var_4 ; var_8 ++ ) { for ( int var_9 = 0 ; var_9 < var_5 ; var_9 ++ ) { var_6 [ var_8 ] [ var_9 ] = var_0 [ var_8 ] [ var_9 ] == '1' ? 1 : 0 ; var_7 = Math . max ( var_6 [ var_8 ] [ var_9 ] , var_7 ) ; } } for ( int var_8 = 1 ; var_8 < var_4 ; var_8 ++ ) { for ( int var_9 = 1 ; var_9 < var_5 ; var_9 ++ ) { if ( var_0 [ var_8 ] [ var_9 ] == '1' ) { var_6 [ var_8 ] [ var_9 ] = Math . min ( Math . min ( var_6 [ var_8 - 1 ] [ var_9 ] , var_6 [ var_8 ] [ var_9 - 1 ] ) , var_6 [ var_8 - 1 ] [ var_9 - 1 ] ) + 1 ; var_7 = Math . max ( var_6 [ var_8 ] [ var_9 ] , var_7 ) ; } } } return var_7 * var_7 ; }
516
<awangdev>1267. Count Servers that Communicate_2.java
private int dfs(int[][] grid, int i, int j, boolean[][] visited) { if (visited[i][j] || grid[i][j] == 0) return 0; visited[i][j] = true; int count = 1; for (int x = 0; x < grid.length; x++) { count += dfs(grid, x, j, visited); } for (int y = 0; y < grid[0].length; y++) { count += dfs(grid, i, y, visited); } return count; }
private int sample_funcname ( int [ ] [ ] grid , int i , int j , boolean [ ] [ ] visited ) { if ( visited [ i ] [ j ] || grid [ i ] [ j ] == 0 ) return 0 ; visited [ i ] [ j ] = true ; int count = 1 ; for ( int x = 0 ; x < grid . length ; x ++ ) { count += dfs ( grid , x , j , visited ) ; } for ( int y = 0 ; y < grid [ 0 ] . length ; y ++ ) { count += dfs ( grid , i , y , visited ) ; } return count ; }
517
<awangdev>Maximum Subarray II_3.java
public int maxTwoSubArrays(List<Integer> nums) { if (nums == null || nums.size() == 0) { return 0; } int n = nums.size(); int[] dpLeft = new int[2]; int[] dpRight = new int[2]; dpLeft[0] = 0; dpRight[n % 2] = 0; int[] maxLeft = new int[n + 1];; int[] maxRight = new int[n + 1]; maxLeft[0] = Integer.MIN_VALUE; maxRight[n] = Integer.MIN_VALUE; for (int i = 1; i <= n; i++) { dpLeft[i % 2] = Math.max(dpLeft[(i - 1) % 2] + nums.get(i - 1), nums.get(i - 1)); maxLeft[i] = Math.max(maxLeft[i - 1], dpLeft[i % 2]); int j = n - i; dpRight[j % 2] = Math.max(dpRight[(j + 1) % 2] + nums.get(j), nums.get(j)); maxRight[j] = Math.max(maxRight[j + 1], dpRight[j % 2]); } int max = Integer.MIN_VALUE; for (int i = 1; i < n; i++) { max = Math.max(max, maxLeft[i] + maxRight[i]); } return max; }
public int sample_funcname ( List < Integer > var_2 ) { if ( var_2 == null || var_2 . size ( ) == 0 ) { return 0 ; } int var_6 = var_2 . size ( ) ; int [ ] var_8 = new int [ 2 ] ; int [ ] var_9 = new int [ 2 ] ; var_8 [ 0 ] = 0 ; var_9 [ var_6 % 2 ] = 0 ; int [ ] var_11 = new int [ var_6 + 1 ] ; ; int [ ] var_12 = new int [ var_6 + 1 ] ; var_11 [ 0 ] = Integer . MIN_VALUE ; var_12 [ var_6 ] = Integer . MIN_VALUE ; for ( int var_14 = 1 ; var_14 <= var_6 ; var_14 ++ ) { var_8 [ var_14 % 2 ] = Math . max ( var_8 [ ( var_14 - 1 ) % 2 ] + var_2 . get ( var_14 - 1 ) , var_2 . get ( var_14 - 1 ) ) ; var_11 [ var_14 ] = Math . max ( var_11 [ var_14 - 1 ] , var_8 [ var_14 % 2 ] ) ; int var_18 = var_6 - var_14 ; var_9 [ var_18 % 2 ] = Math . max ( var_9 [ ( var_18 + 1 ) % 2 ] + var_2 . get ( var_18 ) , var_2 . get ( var_18 ) ) ; var_12 [ var_18 ] = Math . max ( var_12 [ var_18 + 1 ] , var_9 [ var_18 % 2 ] ) ; } int max = Integer . MIN_VALUE ; for ( int var_14 = 1 ; var_14 < var_6 ; var_14 ++ ) { max = Math . max ( max , var_11 [ var_14 ] + var_12 [ var_14 ] ) ; } return max ; }
518
<awangdev>[lint]. 2 Sum II_1.java
public int twoSum2(int[] nums, int target) { if (nums == null || nums.length == 0) { return 0; } int count = 0; int left = 0; int right = nums.length - 1; Arrays.sort(nums); while (left < right) { if (nums[left] + nums[right] > target) { count += (right - left); right--; } else { left++; } } return count; }
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_6 = 0 ; int var_8 = var_0 . length - 1 ; Arrays . sort ( var_0 ) ; while ( var_6 < var_8 ) { if ( var_0 [ var_6 ] + var_0 [ var_8 ] > var_1 ) { var_5 += ( var_8 - var_6 ) ; var_8 -- ; } else { var_6 ++ ; } } return var_5 ; }
519
<awangdev>Best Time to Buy and Sell Stock IV_2.java
public int maxProfit(int k, int[] prices) { if (prices == null || prices.length == 0 || k <= 0) { return 0; } int profit = 0; int n = prices.length; int statusLength = 2 * k + 1; if (k >= n/2) { for (int i = 1; i < n; i++) { if (prices[i] > prices[i - 1]) { profit += prices[i] - prices[i - 1]; } } return profit; } int[][] dp = new int[2][statusLength]; dp[0][0] = 0; for (int i = 1; i < n; i++) { for (int j = 1; j < statusLength; j++) { if (j % 2 == 0) { dp[i % 2][j] = Math.max(dp[(i - 1) % 2][j], dp[(i - 1) % 2][j - 1] + prices[i] - prices[i - 1]); profit = Math.max(profit, dp[i % 2][j]); } else { dp[i % 2][j] = Math.max(dp[(i - 1) % 2][j] + prices[i] - prices[i - 1], dp[(i - 1) % 2][j - 1]); } } } return profit; }
public int sample_funcname ( int var_0 , int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 || var_0 <= 0 ) { return 0 ; } int var_5 = 0 ; int var_6 = var_1 . length ; int var_9 = 2 * var_0 + 1 ; if ( var_0 >= var_6 / 2 ) { for ( int var_10 = 1 ; var_10 < var_6 ; var_10 ++ ) { if ( var_1 [ var_10 ] > var_1 [ var_10 - 1 ] ) { var_5 += var_1 [ var_10 ] - var_1 [ var_10 - 1 ] ; } } return var_5 ; } int [ ] [ ] var_11 = new int [ 2 ] [ var_9 ] ; var_11 [ 0 ] [ 0 ] = 0 ; for ( int var_10 = 1 ; var_10 < var_6 ; var_10 ++ ) { for ( int var_12 = 1 ; var_12 < var_9 ; var_12 ++ ) { if ( var_12 % 2 == 0 ) { var_11 [ var_10 % 2 ] [ var_12 ] = Math . max ( var_11 [ ( var_10 - 1 ) % 2 ] [ var_12 ] , var_11 [ ( var_10 - 1 ) % 2 ] [ var_12 - 1 ] + var_1 [ var_10 ] - var_1 [ var_10 - 1 ] ) ; var_5 = Math . max ( var_5 , var_11 [ var_10 % 2 ] [ var_12 ] ) ; } else { var_11 [ var_10 % 2 ] [ var_12 ] = Math . max ( var_11 [ ( var_10 - 1 ) % 2 ] [ var_12 ] + var_1 [ var_10 ] - var_1 [ var_10 - 1 ] , var_11 [ ( var_10 - 1 ) % 2 ] [ var_12 - 1 ] ) ; } } } return var_5 ; }
520
<awangdev>Palindrome Pairs_1.java
private boolean isPalindrome(String word) { if (word.length() == 1) { return true; } int start = 0; int end = word.length() - 1; while (start < end) { if (word.charAt(start) != word.charAt(end)) { return false; } start++; end--; } return true; }
private boolean var_0 ( String var_2 ) { if ( var_2 . length ( ) == 1 ) { return true ; } int var_6 = 0 ; int var_7 = var_2 . length ( ) - 1 ; while ( var_6 < var_7 ) { if ( var_2 . charAt ( var_6 ) != var_2 . charAt ( var_7 ) ) { return false ; } var_6 ++ ; var_7 -- ; } return true ; }
521
<awangdev>72. Edit Distance_1.java
public int minDistance(String word1, String word2) { if (word1 == null && word2 == null) return 0; if (word1 == null || word2 == null) return word1 == null ? word2.length() : word1.length(); int m = word1.length(), n = word2.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) { dp[i][j] = j; continue; } if (j == 0) { dp[i][j] = i; continue; } if (word1.charAt(i - 1) == word2.charAt(j - 1)) { dp[i][j] = dp[i - 1][j - 1]; } else { dp[i][j] = Math.min(dp[i - 1][j - 1], Math.min(dp[i][j - 1], 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 ) return 0 ; if ( var_1 == null || var_2 == null ) return var_1 == null ? var_2 . length ( ) : var_1 . length ( ) ; int var_6 = var_1 . length ( ) , var_7 = var_2 . length ( ) ; int [ ] [ ] var_9 = new int [ var_6 + 1 ] [ var_7 + 1 ] ; for ( int var_10 = 0 ; var_10 <= var_6 ; var_10 ++ ) { for ( int var_11 = 0 ; var_11 <= var_7 ; var_11 ++ ) { if ( var_10 == 0 ) { var_9 [ var_10 ] [ var_11 ] = var_11 ; continue ; } if ( var_11 == 0 ) { var_9 [ var_10 ] [ var_11 ] = var_10 ; continue ; } if ( var_1 . charAt ( var_10 - 1 ) == var_2 . charAt ( var_11 - 1 ) ) { var_9 [ var_10 ] [ var_11 ] = var_9 [ var_10 - 1 ] [ var_11 - 1 ] ; } else { var_9 [ var_10 ] [ var_11 ] = Math . min ( var_9 [ var_10 - 1 ] [ var_11 - 1 ] , Math . min ( var_9 [ var_10 ] [ var_11 - 1 ] , var_9 [ var_10 - 1 ] [ var_11 ] ) ) + 1 ; } } } return var_9 [ var_6 ] [ var_7 ] ; }
522
<awangdev>Search a 2D Matrix II_1.java
public boolean searchMatrix(int[][] matrix, int target) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return false; } int row = matrix.length; int col = matrix[0].length; int x = row - 1; int y = 0; while (x >= 0 && y < col) { if (matrix[x][y] < target) { y++; } else if (matrix[x][y] > target) { x--; } else { return true; } } return false; }
public boolean var_0 ( int [ ] [ ] var_1 , int var_2 ) { if ( var_1 == null || var_1 . length == 0 || var_1 [ 0 ] . length == 0 ) { return false ; } int var_6 = var_1 . length ; int var_7 = var_1 [ 0 ] . length ; int var_9 = var_6 - 1 ; int var_10 = 0 ; while ( var_9 >= 0 && var_10 < var_7 ) { if ( var_1 [ var_9 ] [ var_10 ] < var_2 ) { var_10 ++ ; } else if ( var_1 [ var_9 ] [ var_10 ] > var_2 ) { var_9 -- ; } else { return true ; } } return false ; }
523
<awangdev>Copy Books_2.java
public int copyBooks(int[] pages, int K) { if (pages == null || pages.length == 0) { return 0; } int n = pages.length; if (K > n) { K = n; } int[][] dp = new int[K + 1][n + 1]; dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[0][i] = Integer.MAX_VALUE; } for (int k = 1; k <= K; k++) { for (int i = 1; i <= n; i++) { int sum = 0; dp[k][i] = Integer.MAX_VALUE; for (int j = i; j >= 0; j--) { dp[k][i] = Math.min(dp[k][i], Math.max(dp[k - 1][j], sum)); if (j > 0) { sum += pages[j - 1]; } } } } return dp[K][n]; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_5 = var_0 . length ; if ( var_1 > var_5 ) { var_1 = var_5 ; } int [ ] [ ] var_7 = new int [ var_1 + 1 ] [ var_5 + 1 ] ; var_7 [ 0 ] [ 0 ] = 0 ; for ( int var_8 = 1 ; var_8 <= var_5 ; var_8 ++ ) { var_7 [ 0 ] [ var_8 ] = Integer . MAX_VALUE ; } for ( int var_11 = 1 ; var_11 <= var_1 ; var_11 ++ ) { for ( int var_8 = 1 ; var_8 <= var_5 ; var_8 ++ ) { int var_12 = 0 ; var_7 [ var_11 ] [ var_8 ] = Integer . MAX_VALUE ; for ( int var_13 = var_8 ; var_13 >= 0 ; var_13 -- ) { var_7 [ var_11 ] [ var_8 ] = Math . min ( var_7 [ var_11 ] [ var_8 ] , Math . max ( var_7 [ var_11 - 1 ] [ var_13 ] , var_12 ) ) ; if ( var_13 > 0 ) { var_12 += var_0 [ var_13 - 1 ] ; } } } } return var_7 [ var_1 ] [ var_5 ] ; }
524
<awangdev>House Robber II_5.java
public int rob(int[] nums) { if (nums == null || nums.length == 0) { return 0; } else if (nums.length == 1) { return nums[0]; } else if (nums.length == 2) { return Math.max(nums[0], nums[1]); } int n = nums.length; int[] dp1 = new int[n]; dp1[0] = nums[0]; dp1[1] = Math.max(nums[0], nums[1]); for (int i = 2; i < n - 1; i++) { dp1[i] = Math.max(dp1[i - 1], dp1[i - 2] + nums[i]); } dp1[n - 1] = dp1[n - 2]; int[] dp2 = new int[n]; dp2[0] = 0; dp2[1] = nums[1]; for (int i = 2; i < n - 2; i++) { dp2[i] = Math.max(dp2[i - 1], dp2[i - 2] + nums[i]); } dp2[n - 1] = dp2[n - 3] + nums[n - 1]; return Math.max(dp2[n - 1], dp1[n - 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 ] ; } else if ( var_0 . length == 2 ) { return Math . max ( var_0 [ 0 ] , var_0 [ 1 ] ) ; } int var_8 = var_0 . length ; int [ ] var_9 = new int [ var_8 ] ; var_9 [ 0 ] = var_0 [ 0 ] ; var_9 [ 1 ] = Math . max ( var_0 [ 0 ] , var_0 [ 1 ] ) ; for ( int var_10 = 2 ; var_10 < var_8 - 1 ; var_10 ++ ) { var_9 [ var_10 ] = Math . max ( var_9 [ var_10 - 1 ] , var_9 [ var_10 - 2 ] + var_0 [ var_10 ] ) ; } var_9 [ var_8 - 1 ] = var_9 [ var_8 - 2 ] ; int [ ] var_11 = new int [ var_8 ] ; var_11 [ 0 ] = 0 ; var_11 [ 1 ] = var_0 [ 1 ] ; for ( int var_10 = 2 ; var_10 < var_8 - 2 ; var_10 ++ ) { var_11 [ var_10 ] = Math . max ( var_11 [ var_10 - 1 ] , var_11 [ var_10 - 2 ] + var_0 [ var_10 ] ) ; } var_11 [ var_8 - 1 ] = var_11 [ var_8 - 3 ] + var_0 [ var_8 - 1 ] ; return Math . max ( var_11 [ var_8 - 1 ] , var_9 [ var_8 - 1 ] ) ; }
525
<awangdev>Combinations_1.java
private void dfs(List<List<Integer>> result, List<Integer> list, int index, int k, int n) { for (int i = index; i <= n; i++) { list.add(i); if (list.size() == k) { result.add(new ArrayList<>(list)); list.remove(list.size() - 1); continue; } dfs(result, list, i + 1, k, n); list.remove(list.size() - 1); } }
private void sample_funcname ( List < List < Integer >> result , List < Integer > list , int index , int k , int n ) { for ( int i = index ; i <= n ; i ++ ) { list . add ( i ) ; if ( list . size ( ) == k ) { result . add ( new ArrayList < > ( list ) ) ; list . remove ( list . size ( ) - 1 ) ; continue ; } dfs ( result , list , i + 1 , k , n ) ; list . remove ( list . size ( ) - 1 ) ; } }
526
<awangdev>843. Guess the Word_2.java
private int countMatch(String a, String b) { int count = 0; for (int i = 0; i < 6; i++) { if (a.charAt(i) == b.charAt(i)) count++; } return count; }
private int sample_funcname ( String var_1 , String var_2 ) { int var_4 = 0 ; for ( int var_5 = 0 ; var_5 < 6 ; var_5 ++ ) { if ( var_1 . charAt ( var_5 ) == var_2 . charAt ( var_5 ) ) var_4 ++ ; } return var_4 ; }
527
<awangdev>266. Palindrome Permutation_1.java
public boolean canPermutePalindrome(String s) { if (s == null || s.length() == 0) return false; int[] chars = new int[256]; for (char c : s.toCharArray()) chars[c]++; int countOdd = 0; for (int i = 0; i < chars.length; i++) { countOdd += chars[i] % 2; if (countOdd > 1) return false; } return true; }
public boolean var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) return false ; int [ ] var_7 = new int [ 256 ] ; for ( char var_9 : var_2 . toCharArray ( ) ) var_7 [ var_9 ] ++ ; int var_10 = 0 ; for ( int var_11 = 0 ; var_11 < var_7 . length ; var_11 ++ ) { var_10 += var_7 [ var_11 ] % 2 ; if ( var_10 > 1 ) return false ; } return true ; }
528
<awangdev>257. Binary Tree Paths_1.java
private String convert(List<String> path) { return String.join("->", path); }
private String var_0 ( List < String > var_3 ) { return String . join ( "->" , var_3 ) ; }
529
<awangdev>1170. Compare Strings by Frequency of the Smallest Character_1.java
private int count(String w) { int[] count = new int[26]; for (char c : w.toCharArray()) count[c - 'a']++; for (int num : count) { if (num != 0) return num; } return 0; }
private int sample_funcname ( String var_1 ) { int [ ] var_3 = new int [ 26 ] ; for ( char var_5 : var_1 . toCharArray ( ) ) var_3 [ var_5 - 'a' ] ++ ; for ( int var_7 : var_3 ) { if ( var_7 != 0 ) return var_7 ; } return 0 ; }
530
<awangdev>Unique Word Abbreviation_1.java
private String convertToAbbr(String word) { if (word == null || word.length() <= 2) { return word; } return word.charAt(0) + String.valueOf(word.length() - 2) + word.charAt(word.length() - 1); }
private String var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) <= 2 ) { return var_2 ; } return var_2 . charAt ( 0 ) + String . valueOf ( var_2 . length ( ) - 2 ) + var_2 . charAt ( var_2 . length ( ) - 1 ) ; }
531
<awangdev>639. Decode Ways II_2.java
private int countDouble(char a, char b) { if (a == '0' || (a >= '3' && a <= '9')) return 0; if (a == '1') return b == '*' ? 9 : 1; if (a == '2') { if (b == '*') return 6; if (b <= '6') return 1; return 0; } if (b >= '0' && b <= '6') return 2; if (b >= '7' && b <= '9') return 1; return 15; }
private int sample_funcname ( char var_0 , char var_1 ) { if ( var_0 == '0' || ( var_0 >= '3' && var_0 <= '9' ) ) return 0 ; if ( var_0 == '1' ) return var_1 == '*' ? 9 : 1 ; if ( var_0 == '2' ) { if ( var_1 == '*' ) return 6 ; if ( var_1 <= '6' ) return 1 ; return 0 ; } if ( var_1 >= '0' && var_1 <= '6' ) return 2 ; if ( var_1 >= '7' && var_1 <= '9' ) return 1 ; return 15 ; }
532
<awangdev>Longest Substring Without Repeating Characters_3.java
public int lengthOfLongestSubstring(String s) { if (s == null || s.length() == 0) { return 0; } HashMap<Character, Integer> map = new HashMap<Character, Integer>(); int head = 0; int max = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (map.containsKey(c)) { if (map.get(c) + 1 > head) { head = map.get(c) + 1; } } map.put(c, i); String str = s.substring(head, i + 1); max = Math.max(max, str.length()); } return max; }
public int sample_funcname ( String var_1 ) { if ( var_1 == null || var_1 . length ( ) == 0 ) { return 0 ; } HashMap < Character , Integer > var_8 = new HashMap < Character , Integer > ( ) ; int var_9 = 0 ; int max = 0 ; for ( int var_11 = 0 ; var_11 < var_1 . length ( ) ; var_11 ++ ) { char var_13 = var_1 . charAt ( var_11 ) ; if ( var_8 . containsKey ( var_13 ) ) { if ( var_8 . get ( var_13 ) + 1 > var_9 ) { var_9 = var_8 . get ( var_13 ) + 1 ; } } var_8 . put ( var_13 , var_11 ) ; String var_19 = var_1 . substring ( var_9 , var_11 + 1 ) ; max = Math . max ( max , var_19 . length ( ) ) ; } return max ; }
533
<awangdev>766. Toeplitz Matrix_1.java
private boolean check(int x, int y, int[][] matrix) { int n = matrix.length, m = matrix[0].length; for (int i = x, j = y; i < n && j < m; i++, j++) { if (matrix[i][j] != matrix[x][y]) return false; } return true; }
private boolean var_0 ( int var_1 , int var_2 , int [ ] [ ] var_3 ) { int var_5 = var_3 . length , var_7 = var_3 [ 0 ] . length ; for ( int var_8 = var_1 , var_9 = var_2 ; var_8 < var_5 && var_9 < var_7 ; var_8 ++ , var_9 ++ ) { if ( var_3 [ var_8 ] [ var_9 ] != var_3 [ var_1 ] [ var_2 ] ) return false ; } return true ; }
534
<awangdev>Fraction to Recurring Decimal_1.java
public String fractionToDecimal(int numerator, int denominator) { long nume = Math.abs((long)numerator); long deno = Math.abs((long)denominator); String sign = (numerator < 0) ^ (denominator < 0) ? "-" : ""; if (deno == 0) { return ""; } else if (nume == 0) { return "0"; } else if (nume % deno == 0) { return sign + nume/deno + ""; } HashMap<Long,Integer> map = new HashMap<Long, Integer>(); StringBuffer rst = new StringBuffer(sign + nume/deno + "."); long end = nume%deno * 10; int i = 0; while (end != 0){ if (map.containsKey(end)) { rst.insert(rst.indexOf(".") + map.get(end) + 1, "("); rst.append(")"); return rst.toString(); } rst.append(end/deno); map.put(end, i++); end = (end % deno) * 10; } return rst.toString(); }
public String var_0 ( int var_1 , int var_2 ) { long var_5 = Math . abs ( ( long ) var_1 ) ; long var_6 = Math . abs ( ( long ) var_2 ) ; String var_11 = ( var_1 < 0 ) ^ ( var_2 < 0 ) ? "-" : "" ; if ( var_6 == 0 ) { return "" ; } else if ( var_5 == 0 ) { return "0" ; } else if ( var_5 % var_6 == 0 ) { return var_11 + var_5 / var_6 + "" ; } HashMap < Long , Integer > var_16 = new HashMap < Long , Integer > ( ) ; StringBuffer var_19 = new StringBuffer ( var_11 + var_5 / var_6 + "." ) ; long var_21 = var_5 % var_6 * 10 ; int var_22 = 0 ; while ( var_21 != 0 ) { if ( var_16 . containsKey ( var_21 ) ) { var_19 . insert ( var_19 . indexOf ( "." ) + var_16 . get ( var_21 ) + 1 , "(" ) ; var_19 . append ( ")" ) ; return var_19 . toString ( ) ; } var_19 . append ( var_21 / var_6 ) ; var_16 . put ( var_21 , var_22 ++ ) ; var_21 = ( var_21 % var_6 ) * 10 ; } return var_19 . toString ( ) ; }
535
<awangdev>438. Find All Anagrams in a String_3.java
private boolean isAnagram(String a, String b) { int[] arr = new int[26]; for (int i = 0; i < a.length(); i++) { arr[a.charAt(i) - 'a']++; arr[b.charAt(i) - 'a']--; } for (int i = 0; i < 26; i++) { if (arr[i] != 0) { return false; } } return true; }
private boolean var_0 ( String var_2 , String var_3 ) { int [ ] var_5 = new int [ 26 ] ; for ( int var_7 = 0 ; var_7 < var_2 . length ( ) ; var_7 ++ ) { var_5 [ var_2 . charAt ( var_7 ) - 'a' ] ++ ; var_5 [ var_3 . charAt ( var_7 ) - 'a' ] -- ; } for ( int var_7 = 0 ; var_7 < 26 ; var_7 ++ ) { if ( var_5 [ var_7 ] != 0 ) { return false ; } } return true ; }
536
<awangdev>Nim Game_2.java
public boolean canWinNim(int n ) { if (n <= 3) { return true; } boolean[] dp = new boolean[n + 1]; dp[0] = true; dp[1] = dp[2] = dp[3] = true; for (int i = 4; i <= n; i++) { dp[i] = !(dp[i - 1] && dp[i - 2] && dp[i - 3]); } return dp[n]; }
public boolean var_0 ( int var_1 ) { if ( var_1 <= 3 ) { return true ; } boolean [ ] var_5 = new boolean [ var_1 + 1 ] ; var_5 [ 0 ] = true ; var_5 [ 1 ] = var_5 [ 2 ] = var_5 [ 3 ] = true ; for ( int var_8 = 4 ; var_8 <= var_1 ; var_8 ++ ) { var_5 [ var_8 ] = ! ( var_5 [ var_8 - 1 ] && var_5 [ var_8 - 2 ] && var_5 [ var_8 - 3 ] ) ; } return var_5 [ var_1 ] ; }
537
<awangdev>665. Non-decreasing Array_1.java
public boolean checkPossibility(int[] nums) { if (nums == null || nums.length < 0) { return false; } else if (nums.length <= 2) { return true; } int count = 0; for (int i = 0; i < nums.length - 1; i++) { if (nums[i] > nums[i + 1]) { if (i >= 1 && nums[i - 1] < nums[i + 1]) { nums[i] = nums[i + 1]; } else if (i >= 1 && nums[i - 1] > nums[i + 1]) { nums[i + 1] = nums[i]; } count++; } if (count >= 2) { return false; } } return true; }
public boolean var_0 ( int [ ] var_1 ) { if ( var_1 == null || var_1 . length < 0 ) { return false ; } else if ( var_1 . length <= 2 ) { return true ; } int var_6 = 0 ; for ( int var_7 = 0 ; var_7 < var_1 . length - 1 ; var_7 ++ ) { if ( var_1 [ var_7 ] > var_1 [ var_7 + 1 ] ) { if ( var_7 >= 1 && var_1 [ var_7 - 1 ] < var_1 [ var_7 + 1 ] ) { var_1 [ var_7 ] = var_1 [ var_7 + 1 ] ; } else if ( var_7 >= 1 && var_1 [ var_7 - 1 ] > var_1 [ var_7 + 1 ] ) { var_1 [ var_7 + 1 ] = var_1 [ var_7 ] ; } var_6 ++ ; } if ( var_6 >= 2 ) { return false ; } } return true ; }
538
<awangdev>Word Search_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 ; }
539
<awangdev>674. Longest Continuous Increasing Subsequence_2.java
public int findLengthOfLCIS(int[] nums) { if (nums == null || nums.length == 0) return 0; int max = 1, size = 1; for (int i = 1; i < nums.length; i++) { if (nums[i] > nums[i - 1]) size++; else size = 1; max = Math.max(size, max); } return max; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int max = 1 , var_6 = 1 ; for ( int var_7 = 1 ; var_7 < var_0 . length ; var_7 ++ ) { if ( var_0 [ var_7 ] > var_0 [ var_7 - 1 ] ) var_6 ++ ; else var_6 = 1 ; max = Math . max ( var_6 , max ) ; } return max ; }
540
<awangdev>Longest Increasing Subsequence_1.java
public int lengthOfLIS(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; int[] dp = new int[n]; int max = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (nums[i] > nums[j]) { dp[i] = Math.max(dp[i], dp[j] + 1); } } max = Math.max(dp[i], max); } return max + 1; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = var_0 . length ; int [ ] var_5 = new int [ var_4 ] ; int max = 0 ; for ( int var_7 = 0 ; var_7 < var_4 ; var_7 ++ ) { for ( int var_8 = 0 ; var_8 < var_7 ; var_8 ++ ) { if ( var_0 [ var_7 ] > var_0 [ var_8 ] ) { var_5 [ var_7 ] = Math . max ( var_5 [ var_7 ] , var_5 [ var_8 ] + 1 ) ; } } max = Math . max ( var_5 [ var_7 ] , max ) ; } return max + 1 ; }
541
<awangdev>Subsets II_6.java
public void dfs(List<List<Integer>> rst, ArrayList<Integer> list, int index, int[] nums) { if (!rst.contains(list)) { rst.add(new ArrayList<Integer>(list)); } for (int i = index; i < nums.length; i++) { list.add(nums[i]); dfs(rst, list, i + 1, nums); list.remove(list.size() - 1); } }
public void sample_funcname ( List < List < Integer >> rst , ArrayList < Integer > list , int index , int [ ] nums ) { if ( ! rst . contains ( list ) ) { rst . add ( new ArrayList < Integer > ( list ) ) ; } for ( int i = index ; i < nums . length ; i ++ ) { list . add ( nums [ i ] ) ; dfs ( rst , list , i + 1 , nums ) ; list . remove ( list . size ( ) - 1 ) ; } }
542
<awangdev>42. Trapping Rain Water_4.java
public int trap(int[] height) { if (height == null || height.length == 0) return 0; final Stack<Integer> stack = new Stack<>(); int total = 0; stack.push(0); for (int i = 1; i < height.length; i++) { int curr = height[i]; if (curr >= height[stack.peek()]) { int bottom = height[stack.pop()]; while (!stack.isEmpty() && curr >= height[stack.peek()]) { int leftBound = stack.pop(); total += (height[leftBound] - bottom) * (i - leftBound - 1); bottom = height[leftBound]; } if (!stack.isEmpty() && curr < height[stack.peek()]) { total += (curr - bottom) * (i - stack.peek() - 1); } } stack.push(i); } return total; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; final Stack < Integer > var_6 = new Stack < > ( ) ; int var_7 = 0 ; var_6 . push ( 0 ) ; for ( int var_10 = 1 ; var_10 < var_0 . length ; var_10 ++ ) { int var_11 = var_0 [ var_10 ] ; if ( var_11 >= var_0 [ var_6 . peek ( ) ] ) { int var_14 = var_0 [ var_6 . pop ( ) ] ; while ( ! var_6 . isEmpty ( ) && var_11 >= var_0 [ var_6 . peek ( ) ] ) { int var_16 = var_6 . pop ( ) ; var_7 += ( var_0 [ var_16 ] - var_14 ) * ( var_10 - var_16 - 1 ) ; var_14 = var_0 [ var_16 ] ; } if ( ! var_6 . isEmpty ( ) && var_11 < var_0 [ var_6 . peek ( ) ] ) { var_7 += ( var_11 - var_14 ) * ( var_10 - var_6 . peek ( ) - 1 ) ; } } var_6 . push ( var_10 ) ; } return var_7 ; }
543
<awangdev>567. Permutation in String_2.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 ; }
544
<awangdev>327. Count of Range Sum_2.java
private long[] calcPreSum(int[] nums) { long[] preSum = new long[nums.length + 1]; for (int i = 1; i < preSum.length; i++) { preSum[i] = preSum[i - 1] + nums[i - 1]; } return preSum; }
private long [ ] sample_funcname ( int [ ] var_0 ) { long [ ] var_3 = new long [ var_0 . length + 1 ] ; for ( int var_4 = 1 ; var_4 < var_3 . length ; var_4 ++ ) { var_3 [ var_4 ] = var_3 [ var_4 - 1 ] + var_0 [ var_4 - 1 ] ; } return var_3 ; }
545
<awangdev>1249. Minimum Remove to Make Valid Parentheses_1.java
public String minRemoveToMakeValid(String s) { Set<Integer> set = new HashSet<>(); Stack<Integer> stack = new Stack<>(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '(') stack.push(i); if (c == ')') { if (!stack.isEmpty()) stack.pop(); else set.add(i); } } while (!stack.isEmpty()) set.add(stack.pop()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { if (!set.contains(i)) sb.append(s.charAt(i)); } return sb.toString(); }
public String var_0 ( String var_2 ) { Set < Integer > var_6 = new HashSet < > ( ) ; Stack < Integer > var_8 = new Stack < > ( ) ; for ( int var_10 = 0 ; var_10 < var_2 . length ( ) ; var_10 ++ ) { char var_13 = var_2 . charAt ( var_10 ) ; if ( var_13 == '(' ) var_8 . push ( var_10 ) ; if ( var_13 == ')' ) { if ( ! var_8 . isEmpty ( ) ) var_8 . pop ( ) ; else var_6 . add ( var_10 ) ; } } while ( ! var_8 . isEmpty ( ) ) var_6 . add ( var_8 . pop ( ) ) ; StringBuffer var_21 = new StringBuffer ( ) ; for ( int var_10 = 0 ; var_10 < var_2 . length ( ) ; var_10 ++ ) { if ( ! var_6 . contains ( var_10 ) ) var_21 . append ( var_2 . charAt ( var_10 ) ) ; } return var_21 . toString ( ) ; }
546
<awangdev>Backspace String Compare_1.java
private String type(String s) { Stack<Character> stack = new Stack<>(); for (char c : s.toCharArray()) { if (c == '#') { if (!stack.isEmpty()) stack.pop(); } else { stack.push(c); } } StringBuffer sb = new StringBuffer(); while (!stack.isEmpty()) { sb.append(stack.pop()); } return sb.toString(); }
private String var_0 ( String var_2 ) { Stack < Character > var_5 = new Stack < > ( ) ; for ( char var_7 : var_2 . toCharArray ( ) ) { if ( var_7 == '#' ) { if ( ! var_5 . isEmpty ( ) ) var_5 . pop ( ) ; } else { var_5 . push ( var_7 ) ; } } StringBuffer var_13 = new StringBuffer ( ) ; while ( ! var_5 . isEmpty ( ) ) { var_13 . append ( var_5 . pop ( ) ) ; } return var_13 . toString ( ) ; }
547
<awangdev>636. Exclusive Time of Functions_1.java
public int[] exclusiveTime(int n, List<String> logs) { int[] rst = new int[n]; Stack<Integer> stack = new Stack<>(); int timestamp = 0; for (String log : logs) { String[] parts = log.split(":"); int task = Integer.parseInt(parts[0]); boolean start = parts[1].equals("start"); int time = Integer.parseInt(parts[2]); if (!stack.isEmpty()) rst[stack.peek()] += time - timestamp; timestamp = time; if (start) stack.push(task); else { int endTask = stack.pop(); rst[endTask] += 1; timestamp++; } } return rst; }
public int [ ] sample_funcname ( int var_0 , List < String > var_3 ) { int [ ] var_4 = new int [ var_0 ] ; Stack < Integer > var_7 = new Stack < > ( ) ; int var_9 = 0 ; for ( String var_10 : var_3 ) { String [ ] var_13 = var_10 . split ( ":" ) ; int var_15 = Integer . parseInt ( var_13 [ 0 ] ) ; boolean var_20 = var_13 [ 1 ] . equals ( "start" ) ; int var_22 = Integer . parseInt ( var_13 [ 2 ] ) ; if ( ! var_7 . isEmpty ( ) ) var_4 [ var_7 . peek ( ) ] += var_22 - var_9 ; var_9 = var_22 ; if ( var_20 ) var_7 . push ( var_15 ) ; else { int var_27 = var_7 . pop ( ) ; var_4 [ var_27 ] += 1 ; var_9 ++ ; } } return var_4 ; }
548
<awangdev>275. H-Index II_1.java
public int hIndex(int[] citations) { if (citations == null || citations.length == 0) { return 0; } int n = citations.length; int start = 0, end = n - 1; while (start + 1 < end) { int mid = start + (end - start) / 2; int h = n - mid; if (citations[mid] < h) start = mid; else { if (mid - 1 >= 0 && citations[mid - 1] <= h) return h; end = mid; } } if (citations[start] >= n - start) return n - start; if (citations[end] >= n - end) return n - end; return 0; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = var_0 . length ; int var_5 = 0 , var_7 = var_4 - 1 ; while ( var_5 + 1 < var_7 ) { int var_9 = var_5 + ( var_7 - var_5 ) / 2 ; int var_10 = var_4 - var_9 ; if ( var_0 [ var_9 ] < var_10 ) var_5 = var_9 ; else { if ( var_9 - 1 >= 0 && var_0 [ var_9 - 1 ] <= var_10 ) return var_10 ; var_7 = var_9 ; } } if ( var_0 [ var_5 ] >= var_4 - var_5 ) return var_4 - var_5 ; if ( var_0 [ var_7 ] >= var_4 - var_7 ) return var_4 - var_7 ; return 0 ; }
549
<awangdev>694. Number of Distinct Islands_1.java
private boolean validateInput(int[][] 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 ( 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 ] == 0 ; }
550
<awangdev>767. Reorganize String_2.java
private Map<Character, Integer> buildCountMap(String S) { Map<Character, Integer> map = new HashMap<>(); for (char c : S.toCharArray()) { int count = map.getOrDefault(c, 0) + 1; if (count > (S.length() + 1) / 2) return new HashMap<>(); map.put(c, count); } return map; }
private Map < Character , Integer > var_2 ( String var_4 ) { Map < Character , Integer > var_7 = new HashMap < > ( ) ; for ( char var_9 : var_4 . toCharArray ( ) ) { int var_13 = var_7 . getOrDefault ( var_9 , 0 ) + 1 ; if ( var_13 > ( var_4 . length ( ) + 1 ) / 2 ) return new HashMap < > ( ) ; var_7 . put ( var_9 , var_13 ) ; } return var_7 ; }
551
<awangdev>Maximal Rectangle_1.java
private int findLargestRectInHistogram(int[] height) { Stack<Integer> stack = new Stack<>(); int m = height.length; int max = 0; for (int i = 0; i <= m; i++) { int currHeight = i == m ? -1 : height[i]; while (!stack.isEmpty() && currHeight <= height[stack.peek()]) { int peekHeight = height[stack.pop()]; int width = stack.isEmpty() ? i : i - stack.peek() - 1; max = Math.max(max, peekHeight * width); } stack.push(i); } return max; }
private int sample_funcname ( int [ ] var_0 ) { Stack < Integer > var_3 = new Stack < > ( ) ; int var_5 = var_0 . length ; int max = 0 ; for ( int var_8 = 0 ; var_8 <= var_5 ; var_8 ++ ) { int var_10 = var_8 == var_5 ? - 1 : var_0 [ var_8 ] ; while ( ! var_3 . isEmpty ( ) && var_10 <= var_0 [ var_3 . peek ( ) ] ) { int var_14 = var_0 [ var_3 . pop ( ) ] ; int var_15 = var_3 . isEmpty ( ) ? var_8 : var_8 - var_3 . peek ( ) - 1 ; max = Math . max ( max , var_14 * var_15 ) ; } var_3 . push ( var_8 ) ; } return max ; }
552
<awangdev>Next Closest Time_1.java
public String nextClosestTime(String time) { if (time == null || time.length() == 0) { return time; } Set<Integer> nums = new HashSet<>(); for (int i = 0; i < time.length(); i++) { if (time.charAt(i) != ':') { nums.add(time.charAt(i) - '0'); } } Set<String> hh = new HashSet<>(); for (int i : nums) { for (int j : nums) { int num = i * 10 + j; if (num >= 0 && num < 24) { hh.add(i + "" + j); } } } Set<String> mm = new HashSet<>(); for (int i : nums) { for (int j : nums) { int num = i * 10 + j; if (num >= 0 && num < 60) { mm.add(i + "" + j); } } } String result = time; int timeValue = Integer.parseInt(time.substring(0, 2)) * 60 + Integer.parseInt(time.substring(3)); int diff = Integer.MAX_VALUE; for (String h : hh) { for (String m : mm) { String newTime = h + ":" + m; int value = 0; if (newTime.compareTo(time) <= 0) { value = Integer.parseInt(h) * 60 + Integer.parseInt(m) + 1440; } else { value = Integer.parseInt(h) * 60 + Integer.parseInt(m); } if (value - timeValue < diff) { diff = value - timeValue; result = newTime; } } } return result; }
public String var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) { return var_2 ; } Set < Integer > var_9 = new HashSet < > ( ) ; for ( int var_10 = 0 ; var_10 < var_2 . length ( ) ; var_10 ++ ) { if ( var_2 . charAt ( var_10 ) != ':' ) { var_9 . add ( var_2 . charAt ( var_10 ) - '0' ) ; } } Set < String > var_15 = new HashSet < > ( ) ; for ( int var_10 : var_9 ) { for ( int var_16 : var_9 ) { int var_18 = var_10 * 10 + var_16 ; if ( var_18 >= 0 && var_18 < 24 ) { var_15 . add ( var_10 + "" + var_16 ) ; } } } Set < String > var_21 = new HashSet < > ( ) ; for ( int var_10 : var_9 ) { for ( int var_16 : var_9 ) { int var_18 = var_10 * 10 + var_16 ; if ( var_18 >= 0 && var_18 < 60 ) { var_21 . add ( var_10 + "" + var_16 ) ; } } } String var_23 = var_2 ; int var_28 = Integer . parseInt ( var_2 . substring ( 0 , 2 ) ) * 60 + Integer . parseInt ( var_2 . substring ( 3 ) ) ; int var_30 = Integer . MAX_VALUE ; for ( String var_31 : var_15 ) { for ( String var_32 : var_21 ) { String var_34 = var_31 + ":" + var_32 ; int var_35 = 0 ; if ( var_34 . compareTo ( var_2 ) <= 0 ) { var_35 = Integer . parseInt ( var_31 ) * 60 + Integer . parseInt ( var_32 ) + 1440 ; } else { var_35 = Integer . parseInt ( var_31 ) * 60 + Integer . parseInt ( var_32 ) ; } if ( var_35 - var_28 < var_30 ) { var_30 = var_35 - var_28 ; var_23 = var_34 ; } } } return var_23 ; }
553
<awangdev>53. Maximum Subarray_4.java
public int maxSubArray(int[] nums) { if (nums == null || nums.length == 0) return 0; int n = nums.length; int[] dp = new int[2]; dp[0] = 0; int max = Integer.MIN_VALUE; for (int i = 1; i <= n; i++) { dp[i % 2] = Math.max(dp[(i - 1) % 2] + nums[i - 1], nums[i - 1]); max = Math.max(max, dp[i % 2]); } return max; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length ; int [ ] var_6 = new int [ 2 ] ; var_6 [ 0 ] = 0 ; int max = Integer . MIN_VALUE ; for ( int var_11 = 1 ; var_11 <= var_4 ; var_11 ++ ) { var_6 [ var_11 % 2 ] = Math . max ( var_6 [ ( var_11 - 1 ) % 2 ] + var_0 [ var_11 - 1 ] , var_0 [ var_11 - 1 ] ) ; max = Math . max ( max , var_6 [ var_11 % 2 ] ) ; } return max ; }
554
<awangdev>152. Maximum Product Subarray_3.java
public int maxProduct(int[] nums) { int n = nums.length; int[] maxProduct = new int[n], minProduct = new int[n]; maxProduct[0] = nums[0]; minProduct[0] = nums[0]; int max = nums[0]; for (int i = 1; i < n; i++) { int num = nums[i]; maxProduct[i] = Math.max(num, Math.max(maxProduct[i - 1] * num, minProduct[i - 1] * num)); minProduct[i] = Math.min(num, Math.min(minProduct[i - 1] * num, maxProduct[i - 1] * num)); max = Math.max(max, maxProduct[i]); } return max; }
public int sample_funcname ( int [ ] var_0 ) { int var_2 = var_0 . length ; int [ ] var_3 = new int [ var_2 ] , var_4 = new int [ var_2 ] ; var_3 [ 0 ] = var_0 [ 0 ] ; var_4 [ 0 ] = var_0 [ 0 ] ; int max = var_0 [ 0 ] ; for ( int var_8 = 1 ; var_8 < var_2 ; var_8 ++ ) { int var_9 = var_0 [ var_8 ] ; var_3 [ var_8 ] = Math . max ( var_9 , Math . max ( var_3 [ var_8 - 1 ] * var_9 , var_4 [ var_8 - 1 ] * var_9 ) ) ; var_4 [ var_8 ] = Math . min ( var_9 , Math . min ( var_4 [ var_8 - 1 ] * var_9 , var_3 [ var_8 - 1 ] * var_9 ) ) ; max = Math . max ( max , var_3 [ var_8 ] ) ; } return max ; }
555
<awangdev>46. Permutations_5.java
private void populateQueue(Queue<List<Integer>> queue, List<Integer> list, int[] nums) { for (int num : nums) { if (list.contains(num)) continue; list.add(num); queue.offer(new ArrayList<>(list)); list.remove(list.size() - 1); } }
private void var_0 ( Queue < List < Integer >> var_4 , List < Integer > var_5 , int [ ] var_6 ) { for ( int var_7 : var_6 ) { if ( var_5 . contains ( var_7 ) ) continue ; var_5 . add ( var_7 ) ; var_4 . offer ( new ArrayList < > ( var_5 ) ) ; var_5 . remove ( var_5 . size ( ) - 1 ) ; } }
556
<awangdev>Missing Number_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 ; }
557
<awangdev>283. Move Zeroes_1.java
public void moveZeroes(int[] nums) { if (nums == null) return; int index = 0, n = nums.length; for (int i = 0; i < n; i++) { if (nums[i] != 0) nums[index++] = nums[i]; } for (int i = index; i < n; i++) { nums[i] = 0; } }
public void var_0 ( int [ ] var_1 ) { if ( var_1 == null ) return ; int var_4 = 0 , var_6 = var_1 . length ; for ( int var_7 = 0 ; var_7 < var_6 ; var_7 ++ ) { if ( var_1 [ var_7 ] != 0 ) var_1 [ var_4 ++ ] = var_1 [ var_7 ] ; } for ( int var_7 = var_4 ; var_7 < var_6 ; var_7 ++ ) { var_1 [ var_7 ] = 0 ; } }
558
<awangdev>680. Valid Palindrome II_1.java
public boolean validate(String s, int start, int end, boolean state) { if (start > end) return false; while (start < end) { if (s.charAt(start) == s.charAt(end)) { start++; end--; continue; } else if (state) { return validate(s, start + 1, end, false) || validate(s, start, end - 1, false); } return false; } return true; }
public boolean sample_funcname ( String s , int start , int end , boolean state ) { if ( start > end ) return false ; while ( start < end ) { if ( s . charAt ( start ) == s . charAt ( end ) ) { start ++ ; end -- ; continue ; } else if ( state ) { return validate ( s , start + 1 , end , false ) || validate ( s , start , end - 1 , false ) ; } return false ; } return true ; }
559
<awangdev>349. Intersection of Two Arrays_1.java
public int[] intersection(int[] nums1, int[] nums2) { Set<Integer> set = new HashSet<>(); for (int num : nums1) set.add(num); Set<Integer> rst = new HashSet<>(); for (int num: nums2) { if (set.contains(num)) rst.add(num); } int i = 0; int[] result = new int[rst.size()]; for (int num : rst) result[i++] = num; return result; }
public int [ ] sample_funcname ( int [ ] var_0 , int [ ] var_1 ) { Set < Integer > var_5 = new HashSet < > ( ) ; for ( int var_6 : var_0 ) var_5 . add ( var_6 ) ; Set < Integer > var_8 = new HashSet < > ( ) ; for ( int var_6 : var_1 ) { if ( var_5 . contains ( var_6 ) ) var_8 . add ( var_6 ) ; } int var_11 = 0 ; int [ ] var_13 = new int [ var_8 . size ( ) ] ; for ( int var_6 : var_8 ) var_13 [ var_11 ++ ] = var_6 ; return var_13 ; }
560
<awangdev>Backpack II_3.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[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 = 1; j <= m; j++) { dp[i][j] = dp[i - 1][j]; if (j - A[i - 1] >= 0 && dp[i - 1][j - A[i - 1]] != -1) { dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - A[i - 1]] + V[i - 1]); } } } int rst = 0; for (int j = 0; j <= m; j++) { if (dp[n][j] != -1) { rst = Math.max(rst, dp[n][j]); } } return rst; }
public int sample_funcname ( int var_0 , int [ ] var_1 , int var_2 [ ] ) { if ( var_1 == null || var_2 == null || var_1 . length != var_2 . length ) { return 0 ; } int var_6 = var_1 . length ; int [ ] [ ] var_8 = new int [ var_6 + 1 ] [ var_0 + 1 ] ; for ( int var_9 = 0 ; var_9 <= var_0 ; 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 = 1 ; 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 - 1 ] [ var_9 - var_1 [ 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_1 [ var_10 - 1 ] ] + var_2 [ var_10 - 1 ] ) ; } } } int var_13 = 0 ; for ( int var_9 = 0 ; var_9 <= var_0 ; var_9 ++ ) { if ( var_8 [ var_6 ] [ var_9 ] != - 1 ) { var_13 = Math . max ( var_13 , var_8 [ var_6 ] [ var_9 ] ) ; } } return var_13 ; }
561
<awangdev>Brick Wall_1.java
private boolean validate(List<List<Integer>> wall) { return wall == null || wall.size() == 0 || wall.get(0) == null || wall.get(0).size() == 0; }
private boolean var_0 ( List < List < Integer >> var_3 ) { return var_3 == null || var_3 . size ( ) == 0 || var_3 . get ( 0 ) == null || var_3 . get ( 0 ) . size ( ) == 0 ; }
562
<awangdev>39. Combination Sum_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++) { 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, 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 ++ ) { 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 , target - value ) ; list . remove ( list . size ( ) - 1 ) ; } }
563
<awangdev>Russian Doll Envelopes_1.java
public int maxEnvelopes(int[][] envelopes) { if (envelopes == null || envelopes.length == 0 || envelopes[0] == null || envelopes[0].length == 0) { return 0; } Arrays.sort(envelopes, new Comparator<int[]>() { public int compare (int[] a, int[] b) { if (a[0] == b[0]) { return a[1] - b[1]; } else { return a[0] - b[0]; } } }); int n = envelopes.length; int[] dp = new int[n]; int max = 0; for (int i = 0; i < n; i++) { dp[i] = 1; for (int j = 0; j < i; j++) { if(envelopes[j][0] < envelopes[i][0] && envelopes[j][1] < envelopes[i][1]) { dp[i] = Math.max(dp[i], dp[j] + 1); } } max = Math.max(max, dp[i]); } return max; }
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 ; } Arrays . sort ( var_0 , new Comparator < int [ ] > ( ) { public int compare ( int [ ] var_8 , int [ ] var_9 ) { if ( var_8 [ 0 ] == var_9 [ 0 ] ) { return var_8 [ 1 ] - var_9 [ 1 ] ; } else { return var_8 [ 0 ] - var_9 [ 0 ] ; } } } ) ; int var_11 = var_0 . length ; int [ ] var_12 = new int [ var_11 ] ; int max = 0 ; for ( int var_14 = 0 ; var_14 < var_11 ; var_14 ++ ) { var_12 [ var_14 ] = 1 ; for ( int var_15 = 0 ; var_15 < var_14 ; var_15 ++ ) { if ( var_0 [ var_15 ] [ 0 ] < var_0 [ var_14 ] [ 0 ] && var_0 [ var_15 ] [ 1 ] < var_0 [ var_14 ] [ 1 ] ) { var_12 [ var_14 ] = Math . max ( var_12 [ var_14 ] , var_12 [ var_15 ] + 1 ) ; } } max = Math . max ( max , var_12 [ var_14 ] ) ; } return max ; }
564
<awangdev>221. Maximal Square_1.java
public int maximalSquare(char[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0] == null || matrix[0].length == 0) return 0; int m = matrix.length, n = matrix[0].length; int[][] dp = new int[m + 1][n + 1]; int maxLen = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (matrix[i - 1][j - 1] == '0') continue; dp[i][j] = Math.min(Math.min(dp[i][j-1], dp[i-1][j]), dp[i-1][j-1]) + 1; maxLen = Math.max(maxLen, dp[i][j]); } } return maxLen * maxLen; }
public int sample_funcname ( char [ ] [ ] 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_7 = new int [ var_4 + 1 ] [ var_5 + 1 ] ; int var_8 = 0 ; for ( int var_9 = 1 ; var_9 <= var_4 ; var_9 ++ ) { for ( int var_10 = 1 ; var_10 <= var_5 ; var_10 ++ ) { if ( var_0 [ var_9 - 1 ] [ var_10 - 1 ] == '0' ) continue ; var_7 [ var_9 ] [ var_10 ] = Math . min ( Math . min ( var_7 [ var_9 ] [ var_10 - 1 ] , var_7 [ var_9 - 1 ] [ var_10 ] ) , var_7 [ var_9 - 1 ] [ var_10 - 1 ] ) + 1 ; var_8 = Math . max ( var_8 , var_7 [ var_9 ] [ var_10 ] ) ; } } return var_8 * var_8 ; }
565
<awangdev>51. N-Queens_3.java
private boolean validate(List<Integer> list, int newColNum) { int newRowNum = list.size(); for (int rowNum = 0; rowNum < list.size(); rowNum++) { int colNum = list.get(rowNum); if (colNum == newColNum || Math.abs(rowNum - newRowNum) == Math.abs(colNum - newColNum)) { return false; } } return true; }
private boolean var_0 ( List < Integer > var_3 , int var_4 ) { int var_6 = var_3 . size ( ) ; for ( int var_8 = 0 ; var_8 < var_3 . size ( ) ; var_8 ++ ) { int var_10 = var_3 . get ( var_8 ) ; if ( var_10 == var_4 || Math . abs ( var_8 - var_6 ) == Math . abs ( var_10 - var_4 ) ) { return false ; } } return true ; }
566
<awangdev>Palindromic Substrings_1.java
private boolean[][] buildPalin(String s) { int n = s.length(); boolean[][] isPalin = new boolean[n][n]; for (int i = 0; i < n; i++) isPalin[i][i] = true; for (int j = 0; j < n; j++) { for (int i = 0; i <= j; i++) { isPalin[i][j] = s.charAt(i) == s.charAt(j) && (j - i <= 1 || isPalin[i + 1][j - 1]); } } return isPalin; }
private boolean [ ] [ ] var_0 ( String var_2 ) { int var_4 = var_2 . length ( ) ; boolean [ ] [ ] var_6 = new boolean [ var_4 ] [ var_4 ] ; for ( int var_8 = 0 ; var_8 < var_4 ; var_8 ++ ) var_6 [ var_8 ] [ var_8 ] = true ; for ( int var_9 = 0 ; var_9 < var_4 ; var_9 ++ ) { for ( int var_8 = 0 ; var_8 <= var_9 ; var_8 ++ ) { var_6 [ var_8 ] [ var_9 ] = var_2 . charAt ( var_8 ) == var_2 . charAt ( var_9 ) && ( var_9 - var_8 <= 1 || var_6 [ var_8 + 1 ] [ var_9 - 1 ] ) ; } } return var_6 ; }
567
<awangdev>1004. Max Consecutive Ones III_1.java
public int longestOnes(int[] A, int k) { int left = 0, right = 0, n = A.length; while (right < n) { if (A[right++] == 0) k--; if (k < 0) { if (A[left] == 0) k++; left++; } } return right - left; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { int var_3 = 0 , var_4 = 0 , var_6 = var_0 . length ; while ( var_4 < var_6 ) { if ( var_0 [ var_4 ++ ] == 0 ) var_1 -- ; if ( var_1 < 0 ) { if ( var_0 [ var_3 ] == 0 ) var_1 ++ ; var_3 ++ ; } } return var_4 - var_3 ; }
568
<awangdev>Sort Colors_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 ; }
569
<awangdev>415. Add Strings_3.java
private String convertToString(int[] result) { int n = result[result.length - 1] == 0 ? result.length - 1: result.length; StringBuffer sb = new StringBuffer(); for (int i = 0; i < n; i++) { char c = (char)('0' + result[n - i - 1]); sb.append(c); } return sb.toString(); }
private String var_0 ( int [ ] var_1 ) { int var_5 = var_1 [ var_1 . length - 1 ] == 0 ? var_1 . length - 1 : var_1 . length ; StringBuffer var_7 = new StringBuffer ( ) ; for ( int var_8 = 0 ; var_8 < var_5 ; var_8 ++ ) { char var_10 = ( char ) ( '0' + var_1 [ var_5 - var_8 - 1 ] ) ; var_7 . append ( var_10 ) ; } return var_7 . toString ( ) ; }
570
<awangdev>[lint]. 2 Sum II_2.java
public int binarySearch(int[] nums, int target, int start, int end) { int mid; int sum; while (start + 1 < end) { mid = start + (end - start) /2; if (mid - 1 >= 0 && nums[mid-1] <= target && target < nums[mid]) { return mid; } else if (mid + 1 < nums.length && nums[mid] <= target && target < nums[mid + 1]) { return mid + 1; } else if (target < nums[mid]) { end = mid; } else { start = mid; } } if (nums[start] > target) { return start; } return (nums[end] > target) ? end : nums.length; }
public int sample_funcname ( int [ ] var_0 , int var_1 , int var_2 , int var_3 ) { int var_4 ; int var_5 ; while ( var_2 + 1 < var_3 ) { var_4 = var_2 + ( var_3 - var_2 ) / 2 ; if ( var_4 - 1 >= 0 && var_0 [ var_4 - 1 ] <= var_1 && var_1 < var_0 [ var_4 ] ) { return var_4 ; } else if ( var_4 + 1 < var_0 . length && var_0 [ var_4 ] <= var_1 && var_1 < var_0 [ var_4 + 1 ] ) { return var_4 + 1 ; } else if ( var_1 < var_0 [ var_4 ] ) { var_3 = var_4 ; } else { var_2 = var_4 ; } } if ( var_0 [ var_2 ] > var_1 ) { return var_2 ; } return ( var_0 [ var_3 ] > var_1 ) ? var_3 : var_0 . length ; }
571
<awangdev>198. House Robber_3.java
public int rob(int[] nums) { if (nums == null || nums.length == 0) return 0; int n = nums.length; int[][] dp = new int[n][2]; dp[0][1] = nums[0]; for (int i = 1; i < n; i++) { dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][0]); dp[i][1] = dp[i - 1][0] + 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 ; int var_4 = var_0 . length ; int [ ] [ ] var_6 = new int [ var_4 ] [ 2 ] ; var_6 [ 0 ] [ 1 ] = var_0 [ 0 ] ; for ( int var_8 = 1 ; var_8 < var_4 ; var_8 ++ ) { var_6 [ var_8 ] [ 0 ] = Math . max ( var_6 [ var_8 - 1 ] [ 1 ] , var_6 [ var_8 - 1 ] [ 0 ] ) ; var_6 [ var_8 ] [ 1 ] = var_6 [ var_8 - 1 ] [ 0 ] + var_0 [ var_8 ] ; } return Math . max ( var_6 [ var_4 - 1 ] [ 0 ] , var_6 [ var_4 - 1 ] [ 1 ] ) ; }
572
<awangdev>1267. Count Servers that Communicate_1.java
public int countServers(int[][] grid) { int total = 0; int m = grid.length, n = grid[0].length; int[] row = new int[m], col = new int[n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (grid[i][j] == 1) { total++; row[i]++; col[j]++; } } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (grid[i][j] == 1 && row[i] == 1 && col[j] == 1) { total--; } } } return total; }
public int sample_funcname ( int [ ] [ ] var_0 ) { int var_2 = 0 ; int var_4 = var_0 . length , var_5 = var_0 [ 0 ] . length ; int [ ] var_6 = new int [ var_4 ] , var_7 = new int [ var_5 ] ; for ( int var_8 = 0 ; var_8 < var_4 ; var_8 ++ ) { for ( int var_9 = 0 ; var_9 < var_5 ; var_9 ++ ) { if ( var_0 [ var_8 ] [ var_9 ] == 1 ) { var_2 ++ ; var_6 [ var_8 ] ++ ; var_7 [ var_9 ] ++ ; } } } for ( int var_8 = 0 ; var_8 < var_4 ; var_8 ++ ) { for ( int var_9 = 0 ; var_9 < var_5 ; var_9 ++ ) { if ( var_0 [ var_8 ] [ var_9 ] == 1 && var_6 [ var_8 ] == 1 && var_7 [ var_9 ] == 1 ) { var_2 -- ; } } } return var_2 ; }
573
<awangdev>Palindrome Pairs_2.java
private boolean isPalindrome(String word) { if (word.length() == 1) { return true; } int start = 0; int end = word.length() - 1; while (start < end) { if (word.charAt(start) != word.charAt(end)) { return false; } start++; end--; } return true; }
private boolean var_0 ( String var_2 ) { if ( var_2 . length ( ) == 1 ) { return true ; } int var_6 = 0 ; int var_7 = var_2 . length ( ) - 1 ; while ( var_6 < var_7 ) { if ( var_2 . charAt ( var_6 ) != var_2 . charAt ( var_7 ) ) { return false ; } var_6 ++ ; var_7 -- ; } return true ; }
574
<awangdev>557. Reverse Words in a String III_1.java
public void reverse(char[] s, int start, int end) { while (start < end) { char temp = s[start]; s[start] = s[end]; s[end] = temp; start++; end--; } }
public void var_0 ( char [ ] var_1 , int var_2 , int var_3 ) { while ( var_2 < var_3 ) { char var_4 = var_1 [ var_2 ] ; var_1 [ var_2 ] = var_1 [ var_3 ] ; var_1 [ var_3 ] = var_4 ; var_2 ++ ; var_3 -- ; } }
575
<awangdev>Best Time to Buy and Sell Stock IV_1.java
public int maxProfit(int k, int[] prices) { if (prices == null || prices.length == 0 || k <= 0) { return 0; } int profit = 0; int n = prices.length; int statusLength = 2 * k + 1; if (k >= n/2) { for (int i = 1; i < n; i++) { if (prices[i] > prices[i - 1]) { profit += prices[i] - prices[i - 1]; } } return profit; } int[][] dp = new int[n][statusLength]; dp[0][0] = 0; for (int i = 1; i < n; i++) { for (int j = 1; j < statusLength; j++) { if (j % 2 == 0) { dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1] + prices[i] - prices[i - 1]); profit = Math.max(profit, dp[i][j]); } else { dp[i][j] = Math.max(dp[i - 1][j] + prices[i] - prices[i - 1], dp[i - 1][j - 1]); } } } return profit; }
public int sample_funcname ( int var_0 , int [ ] var_1 ) { if ( var_1 == null || var_1 . length == 0 || var_0 <= 0 ) { return 0 ; } int var_5 = 0 ; int var_6 = var_1 . length ; int var_9 = 2 * var_0 + 1 ; if ( var_0 >= var_6 / 2 ) { for ( int var_10 = 1 ; var_10 < var_6 ; var_10 ++ ) { if ( var_1 [ var_10 ] > var_1 [ var_10 - 1 ] ) { var_5 += var_1 [ var_10 ] - var_1 [ var_10 - 1 ] ; } } return var_5 ; } int [ ] [ ] var_11 = new int [ var_6 ] [ var_9 ] ; var_11 [ 0 ] [ 0 ] = 0 ; for ( int var_10 = 1 ; var_10 < var_6 ; var_10 ++ ) { for ( int var_12 = 1 ; var_12 < var_9 ; var_12 ++ ) { if ( var_12 % 2 == 0 ) { var_11 [ var_10 ] [ var_12 ] = Math . max ( var_11 [ var_10 - 1 ] [ var_12 ] , var_11 [ var_10 - 1 ] [ var_12 - 1 ] + var_1 [ var_10 ] - var_1 [ var_10 - 1 ] ) ; var_5 = Math . max ( var_5 , var_11 [ var_10 ] [ var_12 ] ) ; } else { var_11 [ var_10 ] [ var_12 ] = Math . max ( var_11 [ var_10 - 1 ] [ var_12 ] + var_1 [ var_10 ] - var_1 [ var_10 - 1 ] , var_11 [ var_10 - 1 ] [ var_12 - 1 ] ) ; } } } return var_5 ; }
576
<awangdev>843. Guess the Word_1.java
private int countMatch(String a, String b) { int count = 0; for (int i = 0; i < 6; i++) { if (a.charAt(i) == b.charAt(i)) count++; } return count; }
private int sample_funcname ( String var_1 , String var_2 ) { int var_4 = 0 ; for ( int var_5 = 0 ; var_5 < 6 ; var_5 ++ ) { if ( var_1 . charAt ( var_5 ) == var_2 . charAt ( var_5 ) ) var_4 ++ ; } return var_4 ; }
577
<awangdev>Cosine Similarity_1.java
public double cosineSimilarity(int[] A, int[] B) { if (A == null || B == null || A.length == 0 || B.length == 0 || A.length != B.length) { return 2; } double sumProduct = 0; double sumASq = 0; double sumBSq = 0; for (int i = 0; i < A.length; i++) { sumProduct += A[i]*B[i]; sumASq += A[i] * A[i]; sumBSq += B[i] * B[i]; } if (sumASq == 0 && sumBSq == 0) { return 2.0; } return sumProduct / (Math.sqrt(sumASq) * Math.sqrt(sumBSq)); }
public double sample_funcname ( int [ ] var_0 , int [ ] var_1 ) { if ( var_0 == null || var_1 == null || var_0 . length == 0 || var_1 . length == 0 || var_0 . length != var_1 . length ) { return 2 ; } double var_6 = 0 ; double var_7 = 0 ; double var_8 = 0 ; for ( int var_9 = 0 ; var_9 < var_0 . length ; var_9 ++ ) { var_6 += var_0 [ var_9 ] * var_1 [ var_9 ] ; var_7 += var_0 [ var_9 ] * var_0 [ var_9 ] ; var_8 += var_1 [ var_9 ] * var_1 [ var_9 ] ; } if ( var_7 == 0 && var_8 == 0 ) { return 2.0 ; } return var_6 / ( Math . sqrt ( var_7 ) * Math . sqrt ( var_8 ) ) ; }
578
<awangdev>Maximum XOR of Two Numbers in an Array_1.java
public int findMaximumXOR(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int res = 0, mask = 0; for (int i = 31; i >= 0; i--) { mask = mask | (1 << i); final Set<Integer> set = new HashSet<>(); for (int num : nums) { set.add(num & mask); } int temp = res | (1 << i); for (int prefix : set) { if (set.contains(temp ^ prefix)) { res = temp; break; } } } return res; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_4 = 0 , var_5 = 0 ; for ( int var_7 = 31 ; var_7 >= 0 ; var_7 -- ) { var_5 = var_5 | ( 1 << var_7 ) ; final Set < Integer > var_12 = new HashSet < > ( ) ; for ( int var_13 : var_0 ) { var_12 . add ( var_13 & var_5 ) ; } int var_15 = var_4 | ( 1 << var_7 ) ; for ( int var_16 : var_12 ) { if ( var_12 . contains ( var_15 ^ var_16 ) ) { var_4 = var_15 ; break ; } } } return var_4 ; }
579
<awangdev>Copy Books_1.java
public int copyBooks(int[] pages, int K) { if (pages == null || pages.length == 0) { return 0; } int n = pages.length; if (K > n) { K = n; } int[][] dp = new int[n + 1][K + 1]; dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = Integer.MAX_VALUE; } for (int i = 1; i <= n; i++) { for (int k = 1; k <= K; k++) { int sum = 0; dp[i][k] = Integer.MAX_VALUE; for (int j = i; j >= 0; j--) { dp[i][k] = Math.min(dp[i][k], Math.max(dp[j][k - 1], sum)); if (j > 0) { sum += pages[j - 1]; } } } } return dp[n][K]; }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { if ( var_0 == null || var_0 . length == 0 ) { return 0 ; } int var_5 = var_0 . length ; if ( var_1 > var_5 ) { var_1 = var_5 ; } int [ ] [ ] var_7 = new int [ var_5 + 1 ] [ var_1 + 1 ] ; var_7 [ 0 ] [ 0 ] = 0 ; for ( int var_8 = 1 ; var_8 <= var_5 ; var_8 ++ ) { var_7 [ var_8 ] [ 0 ] = Integer . MAX_VALUE ; } for ( int var_8 = 1 ; var_8 <= var_5 ; var_8 ++ ) { for ( int var_11 = 1 ; var_11 <= var_1 ; var_11 ++ ) { int var_12 = 0 ; var_7 [ var_8 ] [ var_11 ] = Integer . MAX_VALUE ; for ( int var_13 = var_8 ; var_13 >= 0 ; var_13 -- ) { var_7 [ var_8 ] [ var_11 ] = Math . min ( var_7 [ var_8 ] [ var_11 ] , Math . max ( var_7 [ var_13 ] [ var_11 - 1 ] , var_12 ) ) ; if ( var_13 > 0 ) { var_12 += var_0 [ var_13 - 1 ] ; } } } } return var_7 [ var_5 ] [ var_1 ] ; }
580
<awangdev>Combinations_2.java
public void helper(List<List<Integer>> rst, List<Integer> solution, int n, int k, int start) { if (solution.size() == k) { rst.add(new ArrayList(solution)); return; } for (int i = start; i <= n; i++) { solution.add(i); helper(rst, solution, n, k, i + 1); solution.remove(solution.size() - 1); } }
public void sample_funcname ( List < List < Integer >> rst , List < Integer > solution , int n , int k , int start ) { if ( solution . size ( ) == k ) { rst . add ( new ArrayList ( solution ) ) ; return ; } for ( int i = start ; i <= n ; i ++ ) { solution . add ( i ) ; helper ( rst , solution , n , k , i + 1 ) ; solution . remove ( solution . size ( ) - 1 ) ; } }
581
<awangdev>Search a 2D Matrix II_2.java
public boolean searchMatrix(int[][] matrix, int target) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return false; } int row = matrix.length; int col = matrix[0].length; int x = 0; int y = col - 1; while (x < row && y >= 0) { if (matrix[x][y] < target) { x++; } else if (matrix[x][y] > target) { y--; } else { return true; } } return false; }
public boolean var_0 ( int [ ] [ ] var_1 , int var_2 ) { if ( var_1 == null || var_1 . length == 0 || var_1 [ 0 ] . length == 0 ) { return false ; } int var_6 = var_1 . length ; int var_7 = var_1 [ 0 ] . length ; int var_8 = 0 ; int var_10 = var_7 - 1 ; while ( var_8 < var_6 && var_10 >= 0 ) { if ( var_1 [ var_8 ] [ var_10 ] < var_2 ) { var_8 ++ ; } else if ( var_1 [ var_8 ] [ var_10 ] > var_2 ) { var_10 -- ; } else { return true ; } } return false ; }
582
<awangdev>72. Edit Distance_2.java
public int minDistance(String word1, String word2) { if (word1 == null && word2 == null) return 0; if (word1 == null || word2 == null) return word1 == null ? word2.length() : word1.length(); int m = word1.length(); int n = word2.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; } if (word1.charAt(i - 1) == word2.charAt(j - 1)) { dp[i%2][j] = dp[(i - 1)%2][j - 1]; } else { 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; } } } return dp[m%2][n]; }
public int sample_funcname ( String var_1 , String var_2 ) { if ( var_1 == null && var_2 == null ) return 0 ; if ( var_1 == null || var_2 == null ) return var_1 == null ? var_2 . length ( ) : var_1 . length ( ) ; int var_6 = var_1 . length ( ) ; int var_7 = var_2 . length ( ) ; int [ ] [ ] var_10 = new int [ 2 ] [ var_7 + 1 ] ; for ( int var_11 = 0 ; var_11 <= var_6 ; var_11 ++ ) { for ( int var_12 = 0 ; var_12 <= var_7 ; var_12 ++ ) { if ( var_11 == 0 ) { var_10 [ var_11 % 2 ] [ var_12 ] = var_12 ; continue ; } if ( var_12 == 0 ) { var_10 [ var_11 % 2 ] [ var_12 ] = var_11 ; continue ; } if ( var_1 . charAt ( var_11 - 1 ) == var_2 . charAt ( var_12 - 1 ) ) { var_10 [ var_11 % 2 ] [ var_12 ] = var_10 [ ( var_11 - 1 ) % 2 ] [ var_12 - 1 ] ; } else { var_10 [ var_11 % 2 ] [ var_12 ] = Math . min ( var_10 [ ( var_11 - 1 ) % 2 ] [ var_12 - 1 ] , Math . min ( var_10 [ var_11 % 2 ] [ var_12 - 1 ] , var_10 [ ( var_11 - 1 ) % 2 ] [ var_12 ] ) ) + 1 ; } } } return var_10 [ var_6 % 2 ] [ var_7 ] ; }
583
<awangdev>1170. Compare Strings by Frequency of the Smallest Character_2.java
private int calc(int[] wordCounts, int count) { int rst = 0; for (int i = wordCounts.length - 1; i >= 0; i--) { if (wordCounts[i] <= count) break; rst++; } return rst; }
private int sample_funcname ( int [ ] var_0 , int var_1 ) { int var_3 = 0 ; for ( int var_6 = var_0 . length - 1 ; var_6 >= 0 ; var_6 -- ) { if ( var_0 [ var_6 ] <= var_1 ) break ; var_3 ++ ; } return var_3 ; }
584
<awangdev>218. The Skyline Problem_5.java
int rson(int id) { return id * 2 + 2; }
int sample_funcname ( int var_0 ) { return var_0 * 2 + 2 ; }
585
<awangdev>293. Flip Game_3.java
public static void search(char target, char replace, char[] arr, List<String> rst) { int p1 = 0; int p2 = 1; while (p2 <= arr.length - 1) { if (arr[p1] == target && arr[p2] == target) { arr[p1] = replace; arr[p2] = replace; rst.add(new String(arr)); arr[p1] = target; arr[p2] = target; } p1++; p2++; } }
public static void var_0 ( char var_1 , char var_2 , char [ ] var_3 , List < String > var_6 ) { int var_8 = 0 ; int var_10 = 1 ; while ( var_10 <= var_3 . length - 1 ) { if ( var_3 [ var_8 ] == var_1 && var_3 [ var_10 ] == var_1 ) { var_3 [ var_8 ] = var_2 ; var_3 [ var_10 ] = var_2 ; var_6 . add ( new String ( var_3 ) ) ; var_3 [ var_8 ] = var_1 ; var_3 [ var_10 ] = var_1 ; } var_8 ++ ; var_10 ++ ; } }
586
<awangdev>852. Peak Index in a Mountain Array_1.java
public int peakIndexInMountainArray(int[] A) { int start = 1, end = A.length - 2; int mid = start + (end - start)/2; while (start + 1 < end) { mid = start + (end - start)/2; if (A[mid-1] < A[mid] && A[mid] > A[mid+1]) return mid; else if (A[mid-1] < A[mid+1]) start = mid; else if (A[mid-1] > A[mid+1]) end = mid; } return A[start] < A[end] ? end : start; }
public int sample_funcname ( int [ ] var_0 ) { int var_2 = 1 , var_5 = var_0 . length - 2 ; int var_6 = var_2 + ( var_5 - var_2 ) / 2 ; while ( var_2 + 1 < var_5 ) { var_6 = var_2 + ( var_5 - var_2 ) / 2 ; if ( var_0 [ var_6 - 1 ] < var_0 [ var_6 ] && var_0 [ var_6 ] > var_0 [ var_6 + 1 ] ) return var_6 ; else if ( var_0 [ var_6 - 1 ] < var_0 [ var_6 + 1 ] ) var_2 = var_6 ; else if ( var_0 [ var_6 - 1 ] > var_0 [ var_6 + 1 ] ) var_5 = var_6 ; } return var_0 [ var_2 ] < var_0 [ var_5 ] ? var_5 : var_2 ; }
587
<awangdev>266. Palindrome Permutation_2.java
public boolean canPermutePalindrome(String s) { if (s == null || s.length() == 0) { return true; } HashMap<String, Integer> map = new HashMap<String, Integer>(); for (int i = 0; i < s.length(); i++) { String str = s.charAt(i) + ""; if (!map.containsKey(str)) { map.put(str, 1); } else { map.put(str, map.get(str) + 1); } } int countOdd = 0; for (HashMap.Entry<String, Integer> entry : map.entrySet()) { if (entry.getValue() % 2 == 1) { countOdd++; } if (countOdd > 1) { return false; } } return true; }
public boolean var_0 ( String var_2 ) { if ( var_2 == null || var_2 . length ( ) == 0 ) { return true ; } HashMap < String , Integer > var_8 = new HashMap < String , Integer > ( ) ; for ( int var_9 = 0 ; var_9 < var_2 . length ( ) ; var_9 ++ ) { String var_12 = var_2 . charAt ( var_9 ) + "" ; if ( ! var_8 . containsKey ( var_12 ) ) { var_8 . put ( var_12 , 1 ) ; } else { var_8 . put ( var_12 , var_8 . get ( var_12 ) + 1 ) ; } } int var_17 = 0 ; for ( HashMap . Entry < String , Integer > var_19 : var_8 . entrySet ( ) ) { if ( var_19 . getValue ( ) % 2 == 1 ) { var_17 ++ ; } if ( var_17 > 1 ) { return false ; } } return true ; }
588
<awangdev>639. Decode Ways II_1.java
private int countSingle(char c) { if (c == '*') return 9; if (c == '0') return 0; return 1; }
private int sample_funcname ( char var_0 ) { if ( var_0 == '*' ) return 9 ; if ( var_0 == '0' ) return 0 ; return 1 ; }
589
<awangdev>168. Excel Sheet Column Title_1.java
public String convertToTitle(int n) { if (n <= 0) { return null; } StringBuilder sb = new StringBuilder(); while (n > 0) { int remain = n % 26; n = n / 26; if (remain == 0) { sb.append("Z"); n--; } else { sb.append((char)('A' + remain - 1)); } } return sb.reverse().toString(); }
public String var_0 ( int var_1 ) { if ( var_1 <= 0 ) { return null ; } StringBuilder var_5 = new StringBuilder ( ) ; while ( var_1 > 0 ) { int var_7 = var_1 % 26 ; var_1 = var_1 / 26 ; if ( var_7 == 0 ) { var_5 . append ( "Z" ) ; var_1 -- ; } else { var_5 . append ( ( char ) ( 'A' + var_7 - 1 ) ) ; } } return var_5 . reverse ( ) . toString ( ) ; }
590
<awangdev>Plus One_3.java
public int[] plusOne(int[] digits) { if (digits == null || digits.length == 0) { return null; } String str = ""; for (int i = 0; i < digits.length; i++) { str += digits[i]; } long digit = Long.parseLong(str); digit += 1; str = digit + ""; int[] rst = new int[str.length()]; for (int i = 0; i < str.length(); i++) { rst[i] = Character.getNumericValue(str.charAt(i)); } return rst; }
public int [ ] sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) { return null ; } String var_6 = "" ; for ( int var_7 = 0 ; var_7 < var_0 . length ; var_7 ++ ) { var_6 += var_0 [ var_7 ] ; } long var_10 = Long . parseLong ( var_6 ) ; var_10 += 1 ; var_6 = var_10 + "" ; int [ ] var_12 = new int [ var_6 . length ( ) ] ; for ( int var_7 = 0 ; var_7 < var_6 . length ( ) ; var_7 ++ ) { var_12 [ var_7 ] = Character . getNumericValue ( var_6 . charAt ( var_7 ) ) ; } return var_12 ; }
591
<awangdev>122. Best Time to Buy and Sell Stock II_3.java
public int maxProfit(int[] prices) { if (prices == null || prices.length == 0) return 0; int n = prices.length; int[][] dp = new int[n+1][2]; dp[0][0] = dp[0][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]); } return dp[n][1]; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 == null || var_0 . length == 0 ) return 0 ; int var_4 = var_0 . length ; int [ ] [ ] var_7 = new int [ var_4 + 1 ] [ 2 ] ; var_7 [ 0 ] [ 0 ] = var_7 [ 0 ] [ 1 ] = 0 ; var_7 [ 1 ] [ 0 ] = - var_0 [ 0 ] ; for ( int var_8 = 2 ; var_8 <= var_4 ; var_8 ++ ) { var_7 [ var_8 ] [ 0 ] = Math . max ( var_7 [ var_8 - 1 ] [ 0 ] , var_7 [ var_8 - 1 ] [ 1 ] - var_0 [ var_8 - 1 ] ) ; var_7 [ var_8 ] [ 1 ] = Math . max ( var_7 [ var_8 - 1 ] [ 1 ] , var_7 [ var_8 - 1 ] [ 0 ] + var_0 [ var_8 - 1 ] ) ; } return var_7 [ var_4 ] [ 1 ] ; }
592
<awangdev>Hamming Distance_1.java
public int hammingDistance(int x, int y) { int xor = x ^ y; int count = 0; while (xor != 0) { count += xor & 1; xor = xor >> 1; } return count; }
public int sample_funcname ( int var_0 , int var_1 ) { int var_2 = var_0 ^ var_1 ; int var_4 = 0 ; while ( var_2 != 0 ) { var_4 += var_2 & 1 ; var_2 = var_2 >> 1 ; } return var_4 ; }
593
<awangdev>Flip Game II_4.java
public static boolean checkP1Win(String str, int x, boolean isP1) { String s = str.substring(0,x) + "--" + str.substring(x + 2); if (s.indexOf("++") == -1) { return isP1; } for (int i = s.indexOf("++"); i >= 0 && i < s.length() - 1; i = s.indexOf("++")) { if (checkP1Win(s, i, !isP1)) { return true; } s = s.substring(0, i) + "-" + s.substring(i + 1); } return false; }
public static boolean sample_funcname ( String str , int x , boolean isP1 ) { String s = str . substring ( 0 , x ) + "--" + str . substring ( x + 2 ) ; if ( s . indexOf ( "++" ) == - 1 ) { return isP1 ; } for ( int i = s . indexOf ( "++" ) ; i >= 0 && i < s . length ( ) - 1 ; i = s . indexOf ( "++" ) ) { if ( checkP1Win ( s , i , ! isP1 ) ) { return true ; } s = s . substring ( 0 , i ) + "-" + s . substring ( i + 1 ) ; } return false ; }
594
<awangdev>189. Rotate Array_1.java
private void rotateByRange(int[] nums, int x, int y) { while (x >= 0 && x < y) { int temp = nums[x]; nums[x] = nums[y]; nums[y] = temp; x++; y--; } }
private void var_0 ( int [ ] var_1 , int var_2 , int var_3 ) { while ( var_2 >= 0 && var_2 < var_3 ) { int var_5 = var_1 [ var_2 ] ; var_1 [ var_2 ] = var_1 [ var_3 ] ; var_1 [ var_3 ] = var_5 ; var_2 ++ ; var_3 -- ; } }
595
<awangdev>297. Serialize and Deserialize Binary Tree_1.java
private void truncateData(StringBuffer sb) { sb.delete(0, sb.indexOf(",") + 1); }
private void var_0 ( StringBuffer var_2 ) { var_2 . delete ( 0 , var_2 . indexOf ( "," ) + 1 ) ; }
596
<awangdev>766. Toeplitz Matrix_2.java
public boolean isToeplitzMatrix(int[][] matrix) { for (int i = 0; i < matrix.length - 1; i++) { for (int j = 0; j < matrix[i].length - 1; j++) { if (matrix[i][j] != matrix[i + 1][j + 1]) return false; } } return true; }
public boolean var_0 ( int [ ] [ ] var_1 ) { for ( int var_3 = 0 ; var_3 < var_1 . length - 1 ; var_3 ++ ) { for ( int var_6 = 0 ; var_6 < var_1 [ var_3 ] . length - 1 ; var_6 ++ ) { if ( var_1 [ var_3 ] [ var_6 ] != var_1 [ var_3 + 1 ] [ var_6 + 1 ] ) return false ; } } return true ; }
597
<awangdev>Fraction to Recurring Decimal_2.java
public String fractionToDecimal(int numerator, int denominator) { long nume = Math.abs((long)numerator); long deno = Math.abs((long)denominator); String sign = (numerator < 0) ^ (denominator < 0) ? "-" : ""; if (deno == 0) { return ""; } else if (nume == 0) { return "0"; } else if (nume % deno == 0) { return sign + nume/deno + ""; } String rst = sign + nume/deno + "."; long end = nume%deno * 10; HashMap<Integer, Long> map = new HashMap<Integer, Long>(); boolean repeat = false; String endRepeat = ""; int n = 0; while (true){ if (end == 0) { break; } else if (map.containsValue(end)) { repeat = true; break; } map.put(n++, end); end = (end % deno) * 10; } for (int i = 0; i < n; i++) { if (repeat && map.get(i) == end) { rst += "(" + map.get(i)/deno; endRepeat = ")"; repeat = false; } else { rst += map.get(i)/deno; } } return rst + endRepeat; }
public String var_0 ( int var_1 , int var_2 ) { long var_5 = Math . abs ( ( long ) var_1 ) ; long var_6 = Math . abs ( ( long ) var_2 ) ; String var_11 = ( var_1 < 0 ) ^ ( var_2 < 0 ) ? "-" : "" ; if ( var_6 == 0 ) { return "" ; } else if ( var_5 == 0 ) { return "0" ; } else if ( var_5 % var_6 == 0 ) { return var_11 + var_5 / var_6 + "" ; } String var_14 = var_11 + var_5 / var_6 + "." ; long var_16 = var_5 % var_6 * 10 ; HashMap < Integer , Long > var_20 = new HashMap < Integer , Long > ( ) ; boolean var_27 = false ; String var_22 = "" ; int var_23 = 0 ; while ( true ) { if ( var_16 == 0 ) { break ; } else if ( var_20 . containsValue ( var_16 ) ) { var_27 = true ; break ; } var_20 . put ( var_23 ++ , var_16 ) ; var_16 = ( var_16 % var_6 ) * 10 ; } for ( int var_26 = 0 ; var_26 < var_23 ; var_26 ++ ) { if ( var_27 && var_20 . get ( var_26 ) == var_16 ) { var_14 += "(" + var_20 . get ( var_26 ) / var_6 ; var_22 = ")" ; var_27 = false ; } else { var_14 += var_20 . get ( var_26 ) / var_6 ; } } return var_14 + var_22 ; }
598
<awangdev>Word Search_1.java
private boolean validate(char[][] board, int x, int y, char c) { return x < 0 || x >= board.length || y < 0 || y >= board[0].length || board[x][y] != c || board[x][y] == '#'; }
private boolean var_0 ( char [ ] [ ] var_1 , int var_2 , int var_3 , char var_4 ) { return var_2 < 0 || var_2 >= var_1 . length || var_3 < 0 || var_3 >= var_1 [ 0 ] . length || var_1 [ var_2 ] [ var_3 ] != var_4 || var_1 [ var_2 ] [ var_3 ] == '#' ; }
599
<awangdev>Nim Game_1.java
public boolean canWinNim(int n) { return n % 4 != 0; }
public boolean var_0 ( int var_1 ) { return var_1 % 4 != 0 ; }