id
int64 0
1.17k
| comefrom
stringlengths 21
84
| code
stringlengths 50
1.89k
| masked
stringlengths 63
2.47k
|
---|---|---|---|
0 | <qiyuangong>011_Container_With_Most_Water_1.java | public int maxArea(int[] height) {
int maxArea = 0;
int left = 0;
int right = height.length - 1;
while (left < right) {
maxArea = Math.max(maxArea, (right - left) * Math.min(height[left], height[right]));
if (height[left] < height[right]) left++;
else right--;
}
return maxArea;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 ;
int var_3 = 0 ;
int var_6 = var_0 . length - 1 ;
while ( var_3 < var_6 ) {
var_2 = Math . max ( var_2 , ( var_6 - var_3 ) * Math . min ( var_0 [ var_3 ] , var_0 [ var_6 ] ) ) ;
if ( var_0 [ var_3 ] < var_0 [ var_6 ] ) var_3 ++ ;
else var_6 -- ;
}
return var_2 ;
}
|
1 | <qiyuangong>415_Add_Strings_1.java | public String addStrings(String num1, String num2) {
StringBuilder sb = new StringBuilder();
int carry = 0;
for(int i = num1.length() - 1, j = num2.length() - 1; i >= 0 || j >= 0 || carry == 1; i--, j--){
int x = i < 0 ? 0 : num1.charAt(i) - '0';
int y = j < 0 ? 0 : num2.charAt(j) - '0';
sb.append((x + y + carry) % 10);
carry = (x + y + carry) / 10;
}
return sb.reverse().toString();
} | public String var_0 ( String var_2 , String var_3 ) {
StringBuilder var_5 = new StringBuilder ( ) ;
int var_7 = 0 ;
for ( int var_10 = var_2 . length ( ) - 1 , var_11 = var_3 . length ( ) - 1 ;
var_10 >= 0 || var_11 >= 0 || var_7 == 1 ;
var_10 -- , var_11 -- ) {
int var_14 = var_10 < 0 ? 0 : var_2 . charAt ( var_10 ) - '0' ;
int var_15 = var_11 < 0 ? 0 : var_3 . charAt ( var_11 ) - '0' ;
var_5 . append ( ( var_14 + var_15 + var_7 ) % 10 ) ;
var_7 = ( var_14 + var_15 + var_7 ) / 10 ;
}
return var_5 . reverse ( ) . toString ( ) ;
}
|
2 | <qiyuangong>005_Longest_Palindromic_Substring_3.java | private static char[] removeBoundaries(char[] cs) {
if (cs==null || cs.length<3)
return "".toCharArray();
char[] cs2 = new char[(cs.length-1)/2];
for (int i = 0; i<cs2.length; i++) {
cs2[i] = cs[i*2+1];
}
return cs2;
} | private static char [ ] sample_funcname ( char [ ] var_0 ) {
if ( var_0 == null || var_0 . length < 3 ) return "" . toCharArray ( ) ;
char [ ] var_8 = new char [ ( var_0 . length - 1 ) / 2 ] ;
for ( int var_10 = 0 ;
var_10 < var_8 . length ;
var_10 ++ ) {
var_8 [ var_10 ] = var_0 [ var_10 * 2 + 1 ] ;
}
return var_8 ;
}
|
3 | <qiyuangong>804_Unique_Morse_Code_Words_1.java | public int uniqueMorseRepresentations(String[] words) {
String[] MORSE = new String[]{".-","-...","-.-.","-..",".","..-.","--.",
"....","..",".---","-.-",".-..","--","-.",
"---",".--.","--.-",".-.","...","-","..-",
"...-",".--","-..-","-.--","--.."};
Set<String> seen = new HashSet();
for (String word: words) {
StringBuilder code = new StringBuilder();
for (char c: word.toCharArray())
code.append(MORSE[c - 'a']);
seen.add(code.toString());
}
return seen.size();
} | public int sample_funcname ( String [ ] var_1 ) {
String [ ] var_28 = new String [ ] {
".-" , "-..." , "-.-." , "-.." , "." , "..-." , "--." , "...." , ".." , ".---" , "-.-" , ".-.." , "--" , "-." , "---" , ".--." , "--.-" , ".-." , "..." , "-" , "..-" , "...-" , ".--" , "-..-" , "-.--" , "--.." };
Set < String > var_31 = new HashSet ( ) ;
for ( String var_32 : var_1 ) {
StringBuilder var_34 = new StringBuilder ( ) ;
for ( char var_36 : var_32 . toCharArray ( ) ) var_34 . append ( var_28 [ var_36 - 'a' ] ) ;
var_31 . add ( var_34 . toString ( ) ) ;
}
return var_31 . size ( ) ;
}
|
4 | <qiyuangong>654_Maximum_Binary_Tree_1.java | public int max(int[] nums, int l, int r) {
int max_i = l;
for (int i = l; i < r; i++) {
if (nums[max_i] < nums[i])
max_i = i;
}
return max_i;
} | public int sample_funcname ( int [ ] var_0 , int var_1 , int var_2 ) {
int var_3 = var_1 ;
for ( int var_4 = var_1 ;
var_4 < var_2 ;
var_4 ++ ) {
if ( var_0 [ var_3 ] < var_0 [ var_4 ] ) var_3 = var_4 ;
}
return var_3 ;
}
|
5 | <qiyuangong>1323_Maximum_69_Number_1.java | public int maximum69Number (int num) {
return Integer.valueOf(String.valueOf(num).replaceFirst("6", "9"));
} | public int sample_funcname ( int var_0 ) {
return Integer . valueOf ( String . valueOf ( var_0 ) . replaceFirst ( "6" , "9" ) ) ;
}
|
6 | <qiyuangong>692_Top_K_Frequent_Words_2.java | public List<String> topKFrequent(String[] words, int k) {
Map<String, Integer> count = new HashMap();
for (String word: words) {
count.put(word, count.getOrDefault(word, 0) + 1);
}
PriorityQueue<String> heap = new PriorityQueue<String>(
(w1, w2) -> count.get(w1).equals(count.get(w2)) ?
w2.compareTo(w1) : count.get(w1) - count.get(w2) );
for (String word: count.keySet()) {
heap.offer(word);
if (heap.size() > k) heap.poll();
}
List<String> ans = new ArrayList();
while (!heap.isEmpty()) ans.add(heap.poll());
Collections.reverse(ans);
return ans;
} | public List < String > var_1 ( String [ ] var_2 , int var_3 ) {
Map < String , Integer > var_7 = new HashMap ( ) ;
for ( String var_8 : var_2 ) {
var_7 . put ( var_8 , var_7 . getOrDefault ( var_8 , 0 ) + 1 ) ;
}
PriorityQueue < String > var_19 = new PriorityQueue < String > ( ( var_14 , var_17 ) -> var_7 . get ( var_14 ) . equals ( var_7 . get ( var_17 ) ) ? var_17 . compareTo ( var_14 ) : var_7 . get ( var_14 ) - var_7 . get ( var_17 ) ) ;
for ( String var_8 : var_7 . keySet ( ) ) {
var_19 . offer ( var_8 ) ;
if ( var_19 . size ( ) > var_3 ) var_19 . poll ( ) ;
}
List < String > var_26 = new ArrayList ( ) ;
while ( ! var_19 . isEmpty ( ) ) var_26 . add ( var_19 . poll ( ) ) ;
Collections . reverse ( var_26 ) ;
return var_26 ;
}
|
7 | <qiyuangong>204_Count_Primes_1.java | public int countPrimes(int n) {
boolean[] isPrime = new boolean[n];
int count = 0;
Arrays.fill(isPrime, true);
for (int i = 2; i < n; i++) {
if (i * i >= n)
break;
if (!isPrime[i])
continue;
for (int j = i * i; j < n; j += i)
isPrime[j] = false;
}
for (int i = 2; i < n; i++)
if (isPrime[i])
count++;
return count;
} | public int sample_funcname ( int var_0 ) {
boolean [ ] var_2 = new boolean [ var_0 ] ;
int var_4 = 0 ;
Arrays . fill ( var_2 , true ) ;
for ( int var_8 = 2 ;
var_8 < var_0 ;
var_8 ++ ) {
if ( var_8 * var_8 >= var_0 ) break ;
if ( ! var_2 [ var_8 ] ) continue ;
for ( int var_9 = var_8 * var_8 ;
var_9 < var_0 ;
var_9 += var_8 ) var_2 [ var_9 ] = false ;
}
for ( int var_8 = 2 ;
var_8 < var_0 ;
var_8 ++ ) if ( var_2 [ var_8 ] ) var_4 ++ ;
return var_4 ;
}
|
8 | <qiyuangong>007_Reverse_Integer_1.java | public int reverse(int x) {
if (x == 0) return 0;
long res = 0;
while (x != 0) {
res = res * 10 + x % 10;
if (res > Integer.MAX_VALUE || res < Integer.MIN_VALUE)
return 0;
x /= 10;
}
return (int) res;
} | public int sample_funcname ( int var_0 ) {
if ( var_0 == 0 ) return 0 ;
long var_2 = 0 ;
while ( var_0 != 0 ) {
var_2 = var_2 * 10 + var_0 % 10 ;
if ( var_2 > Integer . MAX_VALUE || var_2 < Integer . MIN_VALUE ) return 0 ;
var_0 /= 10 ;
}
return ( int ) var_2 ;
}
|
9 | <qiyuangong>003_Longest_Substring_Without_Repeating_Characters_2.java | public int lengthOfLongestSubstring(String s) {
int[] charMap = new int[256];
Arrays.fill(charMap, -1);
int i = 0, maxLen = 0;
for (int j = 0; j < s.length(); j++) {
if (charMap[s.charAt(j)] >= i) {
i = charMap[s.charAt(j)] + 1;
}
charMap[s.charAt(j)] = j;
maxLen = Math.max(j - i + 1, maxLen);
}
return maxLen;
} | public int sample_funcname ( String var_1 ) {
int [ ] var_3 = new int [ 256 ] ;
Arrays . fill ( var_3 , - 1 ) ;
int var_8 = 0 , var_9 = 0 ;
for ( int var_10 = 0 ;
var_10 < var_1 . length ( ) ;
var_10 ++ ) {
if ( var_3 [ var_1 . charAt ( var_10 ) ] >= var_8 ) {
var_8 = var_3 [ var_1 . charAt ( var_10 ) ] + 1 ;
}
var_3 [ var_1 . charAt ( var_10 ) ] = var_10 ;
var_9 = Math . max ( var_10 - var_8 + 1 , var_9 ) ;
}
return var_9 ;
}
|
10 | <qiyuangong>013_Roman_to_Integer_1.java | public int romanToInt(String s) {
int[] arr = new int['A' + 26];
arr['I'] = 1;
arr['V'] = 5;
arr['X'] = 10;
arr['L'] = 50;
arr['C'] = 100;
arr['D'] = 500;
arr['M'] = 1000;
int result = 0;
int prev = 0;
for (int i = s.length() - 1; i >= 0; i--) {
int current = arr[s.charAt(i)];
result += prev > current ? -current : current;
prev = current;
}
return result;
} | public int sample_funcname ( String var_1 ) {
int [ ] var_4 = new int [ 'A' + 26 ] ;
var_4 [ 'I' ] = 1 ;
var_4 [ 'V' ] = 5 ;
var_4 [ 'X' ] = 10 ;
var_4 [ 'L' ] = 50 ;
var_4 [ 'C' ] = 100 ;
var_4 [ 'D' ] = 500 ;
var_4 [ 'M' ] = 1000 ;
int var_20 = 0 ;
int var_21 = 0 ;
for ( int var_23 = var_1 . length ( ) - 1 ;
var_23 >= 0 ;
var_23 -- ) {
int var_25 = var_4 [ var_1 . charAt ( var_23 ) ] ;
var_20 += var_21 > var_25 ? - var_25 : var_25 ;
var_21 = var_25 ;
}
return var_20 ;
}
|
11 | <qiyuangong>238_Product_of_Array_Except_Self_1.java | public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] res = new int[n];
res[0] = 1;
for (int i = 1; i < n; i++) {
res[i] = res[i - 1] * nums[i - 1];
}
int right = 1;
for (int i = n - 1; i >= 0; i--) {
res[i] *= right;
right *= nums[i];
}
return res;
} | public int [ ] sample_funcname ( int [ ] var_0 ) {
int var_2 = var_0 . length ;
int [ ] var_3 = new int [ var_2 ] ;
var_3 [ 0 ] = 1 ;
for ( int var_6 = 1 ;
var_6 < var_2 ;
var_6 ++ ) {
var_3 [ var_6 ] = var_3 [ var_6 - 1 ] * var_0 [ var_6 - 1 ] ;
}
int var_7 = 1 ;
for ( int var_6 = var_2 - 1 ;
var_6 >= 0 ;
var_6 -- ) {
var_3 [ var_6 ] *= var_7 ;
var_7 *= var_0 [ var_6 ] ;
}
return var_3 ;
}
|
12 | <qiyuangong>581_Shortest_Unsorted_Continuous_Subarray_1.java | public int findUnsortedSubarray(int[] nums) {
Stack < Integer > stack = new Stack < Integer > ();
int l = nums.length, r = 0;
for (int i = 0; i < nums.length; i++) {
while (!stack.isEmpty() && nums[stack.peek()] > nums[i])
l = Math.min(l, stack.pop());
stack.push(i);
}
stack.clear();
for (int i = nums.length - 1; i >= 0; i--) {
while (!stack.isEmpty() && nums[stack.peek()] < nums[i])
r = Math.max(r, stack.pop());
stack.push(i);
}
return r - l > 0 ? r - l + 1 : 0;
} | public int sample_funcname ( int [ ] var_0 ) {
Stack < Integer > var_3 = new Stack < Integer > ( ) ;
int var_5 = var_0 . length , var_7 = 0 ;
for ( int var_8 = 0 ;
var_8 < var_0 . length ;
var_8 ++ ) {
while ( ! var_3 . isEmpty ( ) && var_0 [ var_3 . peek ( ) ] > var_0 [ var_8 ] ) var_5 = Math . min ( var_5 , var_3 . pop ( ) ) ;
var_3 . push ( var_8 ) ;
}
var_3 . clear ( ) ;
for ( int var_8 = var_0 . length - 1 ;
var_8 >= 0 ;
var_8 -- ) {
while ( ! var_3 . isEmpty ( ) && var_0 [ var_3 . peek ( ) ] < var_0 [ var_8 ] ) var_7 = Math . max ( var_7 , var_3 . pop ( ) ) ;
var_3 . push ( var_8 ) ;
}
return var_7 - var_5 > 0 ? var_7 - var_5 + 1 : 0 ;
}
|
13 | <qiyuangong>929_Unique_Email_Addresses_1.java | public int numUniqueEmails(String[] emails) {
HashSet<String> emailSet = new HashSet<>();
for (String email: emails) {
String firstSplit[] = email.split("@");
String secondSplit[] = firstSplit[0].replaceAll(".", "").split("[+]");
emailSet.add(secondSplit[0] + firstSplit[1]);
}
return emailSet.size();
} | public int sample_funcname ( String [ ] var_1 ) {
HashSet < String > var_3 = new HashSet < > ( ) ;
for ( String var_4 : var_1 ) {
String var_7 [ ] = var_4 . split ( "@" ) ;
String var_13 [ ] = var_7 [ 0 ] . replaceAll ( "." , "" ) . split ( "[+]" ) ;
var_3 . add ( var_13 [ 0 ] + var_7 [ 1 ] ) ;
}
return var_3 . size ( ) ;
}
|
14 | <qiyuangong>724_Find_Pivot_Index_1.java | public int pivotIndex(int[] nums) {
int totalsum = 0, leftsum = 0;
for (int i = 0; i < nums.length; i++) totalsum += nums[i];
for (int i = 0; i < nums.length; i++) {
if (leftsum == totalsum - leftsum - nums[i]) return i;
leftsum += nums[i];
}
return -1;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 , var_3 = 0 ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 ++ ) var_2 += var_0 [ var_4 ] ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 ++ ) {
if ( var_3 == var_2 - var_3 - var_0 [ var_4 ] ) return var_4 ;
var_3 += var_0 [ var_4 ] ;
}
return - 1 ;
}
|
15 | <qiyuangong>560_Subarray_Sum_Equals_K_2.java | public int subarraySum(int[] nums, int k) {
int count = 0, sum = 0;
HashMap < Integer, Integer > map = new HashMap < > ();
map.put(0, 1);
for (int i = 0; i < nums.length; i++) {
sum += nums[i];
if (map.containsKey(sum - k))
count += map.get(sum - k);
map.put(sum, map.getOrDefault(sum, 0) + 1);
}
return count;
} | public int sample_funcname ( int [ ] var_0 , int var_1 ) {
int var_3 = 0 , var_4 = 0 ;
HashMap < Integer , Integer > var_7 = new HashMap < > ( ) ;
var_7 . put ( 0 , 1 ) ;
for ( int var_10 = 0 ;
var_10 < var_0 . length ;
var_10 ++ ) {
var_4 += var_0 [ var_10 ] ;
if ( var_7 . containsKey ( var_4 - var_1 ) ) var_3 += var_7 . get ( var_4 - var_1 ) ;
var_7 . put ( var_4 , var_7 . getOrDefault ( var_4 , 0 ) + 1 ) ;
}
return var_3 ;
}
|
16 | <qiyuangong>434_Number_of_Segments_in_a_String_2.java | public int countSegments(String s) {
int segmentCount = 0;
for (int i = 0; i < s.length(); i++) {
if ((i == 0 || s.charAt(i-1) == ' ') && s.charAt(i) != ' ') {
segmentCount++;
}
}
return segmentCount;
} | public int sample_funcname ( String var_1 ) {
int var_3 = 0 ;
for ( int var_4 = 0 ;
var_4 < var_1 . length ( ) ;
var_4 ++ ) {
if ( ( var_4 == 0 || var_1 . charAt ( var_4 - 1 ) == ' ' ) && var_1 . charAt ( var_4 ) != ' ' ) {
var_3 ++ ;
}
}
return var_3 ;
}
|
17 | <qiyuangong>179_Largest_Number_1.java | public int compare(String a, String b) {
String order1 = a + b;
String order2 = b + a;
return order2.compareTo(order1);
} | public int sample_funcname ( String var_1 , String var_2 ) {
String var_3 = var_1 + var_2 ;
String var_4 = var_2 + var_1 ;
return var_4 . compareTo ( var_3 ) ;
}
|
18 | <qiyuangong>784_Letter_Case_Permutation_2.java | public List<String> letterCasePermutation(String S) {
int B = 0;
for (char c: S.toCharArray())
if (Character.isLetter(c))
B++;
List<String> ans = new ArrayList();
for (int bits = 0; bits < 1<<B; bits++) {
int b = 0;
StringBuilder word = new StringBuilder();
for (char letter: S.toCharArray()) {
if (Character.isLetter(letter)) {
if (((bits >> b++) & 1) == 1)
word.append(Character.toLowerCase(letter));
else
word.append(Character.toUpperCase(letter));
} else {
word.append(letter);
}
}
ans.add(word.toString());
}
return ans;
} | public List < String > var_1 ( String var_2 ) {
int var_4 = 0 ;
for ( char var_6 : var_2 . toCharArray ( ) ) if ( Character . isLetter ( var_6 ) ) var_4 ++ ;
List < String > var_11 = new ArrayList ( ) ;
for ( int var_12 = 0 ;
var_12 < 1 << var_4 ;
var_12 ++ ) {
int var_14 = 0 ;
StringBuilder var_16 = new StringBuilder ( ) ;
for ( char var_17 : var_2 . toCharArray ( ) ) {
if ( Character . isLetter ( var_17 ) ) {
if ( ( ( var_12 >> var_14 ++ ) & 1 ) == 1 ) var_16 . append ( Character . toLowerCase ( var_17 ) ) ;
else var_16 . append ( Character . toUpperCase ( var_17 ) ) ;
}
else {
var_16 . append ( var_17 ) ;
}
}
var_11 . add ( var_16 . toString ( ) ) ;
}
return var_11 ;
}
|
19 | <qiyuangong>438_Find_All_Anagrams_in_a_String_2.java | public List<Integer> findAnagrams(String s, String p) {
List<Integer> list = new ArrayList<Integer>();
int ls = s.length(), lp = p.length();
for (int i = 0; i <= ls - lp; i++) {
boolean flag = true;
String sub = s.substring(i, i + lp);
int[] charCnt = new int[256];
for (int j = 0; j < sub.length(); j++) {
charCnt[sub.charAt(j)]++;
}
for (int j = 0; j < lp; j++) {
charCnt[p.charAt(j)]--;
}
for (int j = 0; j < charCnt.length; j++) {
if (charCnt[j] != 0) {
flag = false;
break;
}
}
if (flag) {
list.add(i);
}
}
return list;
} | public List < Integer > var_1 ( String var_3 , String var_4 ) {
List < Integer > var_7 = new ArrayList < Integer > ( ) ;
int var_9 = var_3 . length ( ) , var_10 = var_4 . length ( ) ;
for ( int var_12 = 0 ;
var_12 <= var_9 - var_10 ;
var_12 ++ ) {
boolean var_20 = true ;
String var_15 = var_3 . substring ( var_12 , var_12 + var_10 ) ;
int [ ] var_17 = new int [ 256 ] ;
for ( int var_18 = 0 ;
var_18 < var_15 . length ( ) ;
var_18 ++ ) {
var_17 [ var_15 . charAt ( var_18 ) ] ++ ;
}
for ( int var_18 = 0 ;
var_18 < var_10 ;
var_18 ++ ) {
var_17 [ var_4 . charAt ( var_18 ) ] -- ;
}
for ( int var_18 = 0 ;
var_18 < var_17 . length ;
var_18 ++ ) {
if ( var_17 [ var_18 ] != 0 ) {
var_20 = false ;
break ;
}
}
if ( var_20 ) {
var_7 . add ( var_12 ) ;
}
}
return var_7 ;
}
|
20 | <qiyuangong>479_Largest_Palindrome_Product_1.java | private long createPalindrom(long num) {
String str = num + new StringBuilder().append(num).reverse().toString();
return Long.parseLong(str);
} | private long sample_funcname ( long var_0 ) {
String var_6 = var_0 + new StringBuilder ( ) . append ( var_0 ) . reverse ( ) . toString ( ) ;
return Long . parseLong ( var_6 ) ;
}
|
21 | <qiyuangong>811_Subdomain_Visit_Count_1.java | public List<String> subdomainVisits(String[] cpdomains) {
Map<String, Integer> map = new HashMap();
for (String cpdomain : cpdomains) {
int i = cpdomain.indexOf(' ');
int n = Integer.valueOf(cpdomain.substring(0, i));
String domain = cpdomain.substring(i + 1);
for (i = 0; i < domain.length(); ++i) {
if (domain.charAt(i) == '.') {
String d = domain.substring(i + 1);
map.put(d, map.getOrDefault(d, 0) + n);
}
}
map.put(domain, map.getOrDefault(domain, 0) + n);
}
List<String> res = new ArrayList();
for (String domain : map.keySet()) res.add(map.get(domain) + " " + domain);
return res;
} | public List < String > var_1 ( String [ ] var_2 ) {
Map < String , Integer > var_6 = new HashMap ( ) ;
for ( String var_7 : var_2 ) {
int var_10 = var_7 . indexOf ( ' ' ) ;
int var_14 = Integer . valueOf ( var_7 . substring ( 0 , var_10 ) ) ;
String var_16 = var_7 . substring ( var_10 + 1 ) ;
for ( var_10 = 0 ;
var_10 < var_16 . length ( ) ;
++ var_10 ) {
if ( var_16 . charAt ( var_10 ) == '.' ) {
String var_20 = var_16 . substring ( var_10 + 1 ) ;
var_6 . put ( var_20 , var_6 . getOrDefault ( var_20 , 0 ) + var_14 ) ;
}
}
var_6 . put ( var_16 , var_6 . getOrDefault ( var_16 , 0 ) + var_14 ) ;
}
List < String > var_25 = new ArrayList ( ) ;
for ( String var_16 : var_6 . keySet ( ) ) var_25 . add ( var_6 . get ( var_16 ) + " " + var_16 ) ;
return var_25 ;
}
|
22 | <qiyuangong>1539_Kth_Missing_Positive_Number_1.java | public int findKthPositive(int[] a, int k) {
int B[] = new int[a.length];
for (int i = 0; i < a.length; i++)
B[i] = a[i] - i - 1; // -1 is done as here missing numbers start from 1 and not 0
int lo = 0, hi = B.length - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (B[mid] >= k)
hi = mid - 1;
else
lo = mid + 1;
}
return lo + k;
} | public int sample_funcname ( int [ ] var_0 , int var_1 ) {
int var_3 [ ] = new int [ var_0 . length ] ;
for ( int var_5 = 0 ;
var_5 < var_0 . length ;
var_5 ++ ) var_3 [ var_5 ] = var_0 [ var_5 ] - var_5 - 1 ;
int var_8 = 0 , var_9 = var_3 . length - 1 ;
while ( var_8 <= var_9 ) {
int var_11 = var_8 + ( var_9 - var_8 ) / 2 ;
if ( var_3 [ var_11 ] >= var_1 ) var_9 = var_11 - 1 ;
else var_8 = var_11 + 1 ;
}
return var_8 + var_1 ;
}
|
23 | <qiyuangong>412_Fizz_Buzz_1.java | public List<String> fizzBuzz(int n) {
List<String> res = new ArrayList<>();
for (int i = 1; i <= n; i++) {
String tmp = "";
if (i % 3 == 0) tmp += "Fizz";
if (i % 5 == 0) tmp += "Buzz";
if (tmp.length() == 0) tmp += String.valueOf(i);
res.add(tmp);
}
return res;
} | public List < String > var_1 ( int var_2 ) {
List < String > var_5 = new ArrayList < > ( ) ;
for ( int var_7 = 1 ;
var_7 <= var_2 ;
var_7 ++ ) {
String var_9 = "" ;
if ( var_7 % 3 == 0 ) var_9 += "Fizz" ;
if ( var_7 % 5 == 0 ) var_9 += "Buzz" ;
if ( var_9 . length ( ) == 0 ) var_9 += String . valueOf ( var_7 ) ;
var_5 . add ( var_9 ) ;
}
return var_5 ;
}
|
24 | <qiyuangong>547_Friend_Circles_1.java | public void dfs(int[][] M, int[] visited, int i) {
for (int j = 0; j < M.length; j++) {
if (M[i][j] == 1 && visited[j] == 0) {
visited[j] = 1;
dfs(M, visited, j);
}
}
} | public void sample_funcname ( int [ ] [ ] M , int [ ] visited , int i ) {
for ( int j = 0 ;
j < M . length ;
j ++ ) {
if ( M [ i ] [ j ] == 1 && visited [ j ] == 0 ) {
visited [ j ] = 1 ;
dfs ( M , visited , j ) ;
}
}
}
|
25 | <qiyuangong>973_K_Closest_Points_to_Origin_1.java | private int dist(int[] point) {
return point[0] * point[0] + point[1] * point[1];
} | private int sample_funcname ( int [ ] var_0 ) {
return var_0 [ 0 ] * var_0 [ 0 ] + var_0 [ 1 ] * var_0 [ 1 ] ;
}
|
26 | <qiyuangong>1089_Duplicate_Zeros_1.java | public void duplicateZeros(int[] arr) {
int movePos = 0;
int lastPos = arr.length - 1;
for (int i = 0; i <= lastPos - movePos; i++) {
if (arr[i] == 0) {
if (i == lastPos - movePos) {
arr[lastPos] = 0;
lastPos--;
break;
}
movePos++;
}
}
lastPos = lastPos - movePos;
for (int i = lastPos; i >= 0; i--) {
if (arr[i] == 0) {
arr[i + movePos] = 0;
movePos--;
arr[i + movePos] = 0;
} else {
arr[i + movePos] = arr[i];
}
}
} | public void var_0 ( int [ ] var_1 ) {
int var_3 = 0 ;
int var_6 = var_1 . length - 1 ;
for ( int var_7 = 0 ;
var_7 <= var_6 - var_3 ;
var_7 ++ ) {
if ( var_1 [ var_7 ] == 0 ) {
if ( var_7 == var_6 - var_3 ) {
var_1 [ var_6 ] = 0 ;
var_6 -- ;
break ;
}
var_3 ++ ;
}
}
var_6 = var_6 - var_3 ;
for ( int var_7 = var_6 ;
var_7 >= 0 ;
var_7 -- ) {
if ( var_1 [ var_7 ] == 0 ) {
var_1 [ var_7 + var_3 ] = 0 ;
var_3 -- ;
var_1 [ var_7 + var_3 ] = 0 ;
}
else {
var_1 [ var_7 + var_3 ] = var_1 [ var_7 ] ;
}
}
}
|
27 | <qiyuangong>387_First_Unique_Character_in_a_String_1.java | public int firstUniqChar(String s) {
int freq [] = new int[26];
for(int i = 0; i < s.length(); i ++)
freq [s.charAt(i) - 'a'] ++;
for(int i = 0; i < s.length(); i ++)
if(freq [s.charAt(i) - 'a'] == 1)
return i;
return -1;
} | public int sample_funcname ( String var_1 ) {
int var_3 [ ] = new int [ 26 ] ;
for ( int var_5 = 0 ;
var_5 < var_1 . length ( ) ;
var_5 ++ ) var_3 [ var_1 . charAt ( var_5 ) - 'a' ] ++ ;
for ( int var_5 = 0 ;
var_5 < var_1 . length ( ) ;
var_5 ++ ) if ( var_3 [ var_1 . charAt ( var_5 ) - 'a' ] == 1 ) return var_5 ;
return - 1 ;
}
|
28 | <qiyuangong>771_Jewels_and_Stones_1.java | public int numJewelsInStones(String J, String S) {
int result = 0;
HashSet jHash = new HashSet<>();
for (int j = 0; j < J.length(); j++) {
jHash.add(J.charAt(j));
}
for (int s = 0; s < S.length(); s++) {
if (jHash.contains(S.charAt(s))) {
result++;
}
}
return result;
} | public int sample_funcname ( String var_1 , String var_2 ) {
int var_4 = 0 ;
HashSet var_6 = new HashSet < > ( ) ;
for ( int var_7 = 0 ;
var_7 < var_1 . length ( ) ;
var_7 ++ ) {
var_6 . add ( var_1 . charAt ( var_7 ) ) ;
}
for ( int var_11 = 0 ;
var_11 < var_2 . length ( ) ;
var_11 ++ ) {
if ( var_6 . contains ( var_2 . charAt ( var_11 ) ) ) {
var_4 ++ ;
}
}
return var_4 ;
}
|
29 | <qiyuangong>665_Non-decreasing_Array_1.java | public boolean checkPossibility(int[] nums) {
int brokenPoint = 0;
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] > nums[i + 1]) {
brokenPoint++;
if (brokenPoint >= 2) return false;
if (i - 1 < 0 || nums[i - 1] <= nums[i + 1]) nums[i] = nums[i + 1];
else nums[i + 1] = nums[i];
}
}
return true;
} | public boolean var_0 ( int [ ] var_1 ) {
int var_3 = 0 ;
for ( int var_4 = 0 ;
var_4 < var_1 . length - 1 ;
var_4 ++ ) {
if ( var_1 [ var_4 ] > var_1 [ var_4 + 1 ] ) {
var_3 ++ ;
if ( var_3 >= 2 ) return false ;
if ( var_4 - 1 < 0 || var_1 [ var_4 - 1 ] <= var_1 [ var_4 + 1 ] ) var_1 [ var_4 ] = var_1 [ var_4 + 1 ] ;
else var_1 [ var_4 + 1 ] = var_1 [ var_4 ] ;
}
}
return true ;
}
|
30 | <qiyuangong>009_Palindrome_Number_1.java | public boolean isPalindrome(int x) {
if (x < 0)
return false;
int temp = x;
int len = 0;
while (temp != 0) {
temp /= 10;
len ++;
}
temp = x;
int left, right;
for (int i = 0; i < len / 2; i++) {
right = temp % 10;
left = temp / (int) Math.pow(10, len - 2 * i - 1);
left = left % 10;
if (left != right)
return false;
temp /= 10;
}
return true;
} | public boolean var_0 ( int var_1 ) {
if ( var_1 < 0 ) return false ;
int var_3 = var_1 ;
int var_4 = 0 ;
while ( var_3 != 0 ) {
var_3 /= 10 ;
var_4 ++ ;
}
var_3 = var_1 ;
int var_6 , var_7 ;
for ( int var_8 = 0 ;
var_8 < var_4 / 2 ;
var_8 ++ ) {
var_7 = var_3 % 10 ;
var_6 = var_3 / ( int ) Math . pow ( 10 , var_4 - 2 * var_8 - 1 ) ;
var_6 = var_6 % 10 ;
if ( var_6 != var_7 ) return false ;
var_3 /= 10 ;
}
return true ;
}
|
31 | <qiyuangong>668_Kth_Smallest_Number_in_Multiplication_Table_1.java | public boolean enough(int x, int m, int n, int k) {
int count = 0;
for (int i = 1; i <= m; i++) {
count += Math.min(x / i, n);
}
return count >= k;
} | public boolean var_0 ( int var_1 , int var_2 , int var_3 , int var_4 ) {
int var_6 = 0 ;
for ( int var_8 = 1 ;
var_8 <= var_2 ;
var_8 ++ ) {
var_6 += Math . min ( var_1 / var_8 , var_3 ) ;
}
return var_6 >= var_4 ;
}
|
32 | <qiyuangong>760_Find_Anagram_Mappings_1.java | public int[] anagramMappings(int[] A, int[] B) {
int[] ans = new int[A.length];
HashMap<Integer, Integer> valIndex = new HashMap<>();
for (int i = 0; i < B.length; i++) valIndex.put(B[i], i);
for (int i = 0; i < A.length; i++) ans[i] = valIndex.get(A[i]);
return ans;
} | public int [ ] sample_funcname ( int [ ] var_0 , int [ ] var_1 ) {
int [ ] var_3 = new int [ var_0 . length ] ;
HashMap < Integer , Integer > var_6 = new HashMap < > ( ) ;
for ( int var_8 = 0 ;
var_8 < var_1 . length ;
var_8 ++ ) var_6 . put ( var_1 [ var_8 ] , var_8 ) ;
for ( int var_8 = 0 ;
var_8 < var_0 . length ;
var_8 ++ ) var_3 [ var_8 ] = var_6 . get ( var_0 [ var_8 ] ) ;
return var_3 ;
}
|
33 | <qiyuangong>709_To_Lower_Case_2.java | public String toLowerCase(String str) {
char[] a = str.toCharArray();
for (int i = 0; i < a.length; i++)
if ('A' <= a[i] && a[i] <= 'Z')
a[i] = (char) (a[i] - 'A' + 'a');
return new String(a);
} | public String var_0 ( String var_2 ) {
char [ ] var_4 = var_2 . toCharArray ( ) ;
for ( int var_6 = 0 ;
var_6 < var_4 . length ;
var_6 ++ ) if ( 'A' <= var_4 [ var_6 ] && var_4 [ var_6 ] <= 'Z' ) var_4 [ var_6 ] = ( char ) ( var_4 [ var_6 ] - 'A' + 'a' ) ;
return new String ( var_4 ) ;
}
|
34 | <qiyuangong>005_Longest_Palindromic_Substring_2.java | private static char[] addBoundaries(char[] cs) {
if (cs==null || cs.length==0)
return "||".toCharArray();
char[] cs2 = new char[cs.length*2+1];
for (int i = 0; i<(cs2.length-1); i = i+2) {
cs2[i] = '|';
cs2[i+1] = cs[i/2];
}
cs2[cs2.length-1] = '|';
return cs2;
} | private static char [ ] sample_funcname ( char [ ] var_0 ) {
if ( var_0 == null || var_0 . length == 0 ) return "||" . toCharArray ( ) ;
char [ ] var_8 = new char [ var_0 . length * 2 + 1 ] ;
for ( int var_9 = 0 ;
var_9 < ( var_8 . length - 1 ) ;
var_9 = var_9 + 2 ) {
var_8 [ var_9 ] = '|' ;
var_8 [ var_9 + 1 ] = var_0 [ var_9 / 2 ] ;
}
var_8 [ var_8 . length - 1 ] = '|' ;
return var_8 ;
}
|
35 | <qiyuangong>1108_Defanging_an_IP_Address_1.java | public String defangIPaddr(String address) {
return address.replace(".", "[.]");
} | public String var_0 ( String var_2 ) {
return var_2 . replace ( "." , "[.]" ) ;
}
|
36 | <qiyuangong>1064_Fixed_Point_1.java | public int fixedPoint(int[] A) {
int l = 0;
int h = A.length;
while (l <= h) {
int mid = (l + h) / 2;
if (A[mid] > mid) h = mid - 1;
else if (A[mid] < mid) l = mid + 1;
else return mid;
}
return -1;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 ;
int var_4 = var_0 . length ;
while ( var_2 <= var_4 ) {
int var_6 = ( var_2 + var_4 ) / 2 ;
if ( var_0 [ var_6 ] > var_6 ) var_4 = var_6 - 1 ;
else if ( var_0 [ var_6 ] < var_6 ) var_2 = var_6 + 1 ;
else return var_6 ;
}
return - 1 ;
}
|
37 | <qiyuangong>962_Maximum_Width_Ramp_1.java | public int maxWidthRamp(int[] A) {
int N = A.length;
Integer[] B = new Integer[N];
for (int i = 0; i < N; ++i)
B[i] = i;
Arrays.sort(B, (i, j) -> ((Integer) A[i]).compareTo(A[j]));
int ans = 0;
int m = N;
for (int i: B) {
ans = Math.max(ans, i - m);
m = Math.min(m, i);
}
return ans;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = var_0 . length ;
Integer [ ] var_4 = new Integer [ var_2 ] ;
for ( int var_6 = 0 ;
var_6 < var_2 ;
++ var_6 ) var_4 [ var_6 ] = var_6 ;
Arrays . sort ( var_4 , ( var_6 , var_9 ) -> ( ( Integer ) var_0 [ var_6 ] ) . compareTo ( var_0 [ var_9 ] ) ) ;
int var_11 = 0 ;
int var_12 = var_2 ;
for ( int var_6 : var_4 ) {
var_11 = Math . max ( var_11 , var_6 - var_12 ) ;
var_12 = Math . min ( var_12 , var_6 ) ;
}
return var_11 ;
}
|
38 | <qiyuangong>937_Reorder_Log_Files_1.java | public String[] reorderLogFiles(String[] logs) {
Arrays.sort(logs, (log1, log2) -> {
String[] split1 = log1.split(" ", 2);
String[] split2 = log2.split(" ", 2);
boolean isDigit1 = Character.isDigit(split1[1].charAt(0));
boolean isDigit2 = Character.isDigit(split2[1].charAt(0));
if (!isDigit1 && !isDigit2) {
int cmp = split1[1].compareTo(split2[1]);
if (cmp != 0) return cmp;
return split1[0].compareTo(split2[0]);
}
return isDigit1 ? (isDigit2 ? 0 : 1) : -1;
});
return logs;
} | public String [ ] var_0 ( String [ ] var_2 ) {
Arrays . sort ( var_2 , ( var_5 , var_6 ) -> {
String [ ] var_10 = var_5 . split ( " " , 2 ) ;
String [ ] var_11 = var_6 . split ( " " , 2 ) ;
boolean var_18 = Character . isDigit ( var_10 [ 1 ] . charAt ( 0 ) ) ;
boolean var_19 = Character . isDigit ( var_11 [ 1 ] . charAt ( 0 ) ) ;
if ( ! var_18 && ! var_19 ) {
int var_21 = var_10 [ 1 ] . compareTo ( var_11 [ 1 ] ) ;
if ( var_21 != 0 ) return var_21 ;
return var_10 [ 0 ] . compareTo ( var_11 [ 0 ] ) ;
}
return var_18 ? ( var_19 ? 0 : 1 ) : - 1 ;
}
) ;
return var_2 ;
}
|
39 | <qiyuangong>852_Peak_Index_in_a_Mountain_Array_2.java | public int peakIndexInMountainArray(int[] A) {
int lo = 0, hi = A.length - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (A[mid] < A[mid + 1]) lo = mid + 1;
else hi = mid;
}
return lo;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 , var_5 = var_0 . length - 1 ;
while ( var_2 < var_5 ) {
int var_7 = ( var_2 + var_5 ) / 2 ;
if ( var_0 [ var_7 ] < var_0 [ var_7 + 1 ] ) var_2 = var_7 + 1 ;
else var_5 = var_7 ;
}
return var_2 ;
}
|
40 | <qiyuangong>961_N-Repeated_Element_in_Size_2N_Array_1.java | public int repeatedNTimes(int[] A) {
HashMap<Integer, Integer> hash = new HashMap<>();
int ans = A[0];
for (int n: A) {
int count = hash.getOrDefault(n, 0) + 1;
hash.put(n, count);
if (count >= hash.get(ans)) ans = n;
}
return ans;
} | public int sample_funcname ( int [ ] var_0 ) {
HashMap < Integer , Integer > var_3 = new HashMap < > ( ) ;
int var_5 = var_0 [ 0 ] ;
for ( int var_6 : var_0 ) {
int var_9 = var_3 . getOrDefault ( var_6 , 0 ) + 1 ;
var_3 . put ( var_6 , var_9 ) ;
if ( var_9 >= var_3 . get ( var_5 ) ) var_5 = var_6 ;
}
return var_5 ;
}
|
41 | <qiyuangong>215_Kth_Largest_Element_in_an_Array_1.java | private void exch(int[] a, int i, int j) {
final int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
} | private void var_0 ( int [ ] var_1 , int var_2 , int var_3 ) {
final int var_4 = var_1 [ var_2 ] ;
var_1 [ var_2 ] = var_1 [ var_3 ] ;
var_1 [ var_3 ] = var_4 ;
}
|
42 | <qiyuangong>720_Longest_Word_in_Dictionary_1.java | public String longestWord(String[] words) {
String ans = "";
Set<String> wordset = new HashSet();
for (String word: words) wordset.add(word);
for (String word: words) {
if (word.length() > ans.length() ||
word.length() == ans.length() && word.compareTo(ans) < 0) {
boolean good = true;
for (int k = 1; k < word.length(); ++k) {
if (!wordset.contains(word.substring(0, k))) {
good = false;
break;
}
}
if (good) ans = word;
}
}
return ans;
} | public String var_0 ( String [ ] var_2 ) {
String var_4 = "" ;
Set < String > var_7 = new HashSet ( ) ;
for ( String var_8 : var_2 ) var_7 . add ( var_8 ) ;
for ( String var_8 : var_2 ) {
if ( var_8 . length ( ) > var_4 . length ( ) || var_8 . length ( ) == var_4 . length ( ) && var_8 . compareTo ( var_4 ) < 0 ) {
boolean var_18 = true ;
for ( int var_15 = 1 ;
var_15 < var_8 . length ( ) ;
++ var_15 ) {
if ( ! var_7 . contains ( var_8 . substring ( 0 , var_15 ) ) ) {
var_18 = false ;
break ;
}
}
if ( var_18 ) var_4 = var_8 ;
}
}
return var_4 ;
}
|
43 | <qiyuangong>728_Self_Dividing_Numbers_1.java | public boolean isSelfDiving(int num) {
int digit = num % 10;
int temp = num;
boolean isTrue = true;
while(temp != 0) {
if(digit == 0 || num % digit != 0) {
isTrue = false;
break;
} else {
temp /= 10;
digit = temp % 10;
}
}
return isTrue;
} | public boolean var_0 ( int var_1 ) {
int var_3 = var_1 % 10 ;
int var_4 = var_1 ;
boolean var_7 = true ;
while ( var_4 != 0 ) {
if ( var_3 == 0 || var_1 % var_3 != 0 ) {
var_7 = false ;
break ;
}
else {
var_4 /= 10 ;
var_3 = var_4 % 10 ;
}
}
return var_7 ;
}
|
44 | <qiyuangong>945_Minimum_Increment_to_Make_Array_Unique_1.java | public int minIncrementForUnique(int[] A) {
if (A.length == 0) return 0;
HashSet<Integer> numSet = new HashSet<>();
List<Integer> duplicated = new ArrayList<>();
int res = 0;
Arrays.sort(A);
int left = A[0];
int right = A[A.length - 1];
int holes = right - left + 1;
for (int v: A) {
if (numSet.contains(v)) duplicated.add(v);
else numSet.add(v);
}
holes -= numSet.size();
for (int i = left + 1; i < right; i++) {
if (holes == 0 || duplicated.size() == 0) break;
if (!numSet.contains(i) && i > duplicated.get(0)) {
res += i - duplicated.get(0);
holes --;
duplicated.remove(0);
}
}
if (duplicated.size() == 0) return res;
while (duplicated.size() != 0) {
right += 1;
res += right - duplicated.get(0);
duplicated.remove(0);
}
return res;
} | public int sample_funcname ( int [ ] var_0 ) {
if ( var_0 . length == 0 ) return 0 ;
HashSet < Integer > var_5 = new HashSet < > ( ) ;
List < Integer > var_8 = new ArrayList < > ( ) ;
int var_9 = 0 ;
Arrays . sort ( var_0 ) ;
int var_12 = var_0 [ 0 ] ;
int var_14 = var_0 [ var_0 . length - 1 ] ;
int var_15 = var_14 - var_12 + 1 ;
for ( int var_16 : var_0 ) {
if ( var_5 . contains ( var_16 ) ) var_8 . add ( var_16 ) ;
else var_5 . add ( var_16 ) ;
}
var_15 -= var_5 . size ( ) ;
for ( int var_20 = var_12 + 1 ;
var_20 < var_14 ;
var_20 ++ ) {
if ( var_15 == 0 || var_8 . size ( ) == 0 ) break ;
if ( ! var_5 . contains ( var_20 ) && var_20 > var_8 . get ( 0 ) ) {
var_9 += var_20 - var_8 . get ( 0 ) ;
var_15 -- ;
var_8 . remove ( 0 ) ;
}
}
if ( var_8 . size ( ) == 0 ) return var_9 ;
while ( var_8 . size ( ) != 0 ) {
var_14 += 1 ;
var_9 += var_14 - var_8 . get ( 0 ) ;
var_8 . remove ( 0 ) ;
}
return var_9 ;
}
|
45 | <qiyuangong>751_IP_to_CIDR_3.java | private int bitLength(long x) {
if (x == 0) return 1;
int ans = 0;
while (x > 0) {
x >>= 1;
ans++;
}
return ans;
} | private int sample_funcname ( long var_0 ) {
if ( var_0 == 0 ) return 1 ;
int var_3 = 0 ;
while ( var_0 > 0 ) {
var_0 >>= 1 ;
var_3 ++ ;
}
return var_3 ;
}
|
46 | <qiyuangong>1480_Running_Sum_of_1d_Array_1.java | public int[] runningSum(int[] nums) {
if (nums.length <= 1) return nums;
for (int i = 1; i < nums.length; i++)
nums[i] += nums[i - 1];
return nums;
} | public int [ ] sample_funcname ( int [ ] var_0 ) {
if ( var_0 . length <= 1 ) return var_0 ;
for ( int var_3 = 1 ;
var_3 < var_0 . length ;
var_3 ++ ) var_0 [ var_3 ] += var_0 [ var_3 - 1 ] ;
return var_0 ;
}
|
47 | <qiyuangong>223_Rectangle_Area_1.java | public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int left = Math.max(A, E), right = Math.max(Math.min(C, G), left);
int bottom = Math.max(B, F), top = Math.max(Math.min(D, H), bottom);
return (C - A) * (D - B) - (right - left) * (top - bottom) + (G - E) * (H - F);
} | public int sample_funcname ( int var_0 , int var_1 , int var_2 , int var_3 , int var_4 , int var_5 , int var_6 , int var_7 ) {
int var_10 = Math . max ( var_0 , var_4 ) , var_12 = Math . max ( Math . min ( var_2 , var_6 ) , var_10 ) ;
int var_13 = Math . max ( var_1 , var_5 ) , var_14 = Math . max ( Math . min ( var_3 , var_7 ) , var_13 ) ;
return ( var_2 - var_0 ) * ( var_3 - var_1 ) - ( var_12 - var_10 ) * ( var_14 - var_13 ) + ( var_6 - var_4 ) * ( var_7 - var_5 ) ;
}
|
48 | <qiyuangong>680_Valid_Palindrome_II_1.java | public boolean isPalindromeRange(String s, int i, int j) {
for (int k = i; k <= i + (j - i) / 2; k++) {
if (s.charAt(k) != s.charAt(j - k + i)) return false;
}
return true;
} | public boolean var_0 ( String var_2 , int var_3 , int var_4 ) {
for ( int var_5 = var_3 ;
var_5 <= var_3 + ( var_4 - var_3 ) / 2 ;
var_5 ++ ) {
if ( var_2 . charAt ( var_5 ) != var_2 . charAt ( var_4 - var_5 + var_3 ) ) return false ;
}
return true ;
}
|
49 | <qiyuangong>628_Maximum_Product_of_Three_Numbers_2.java | public int maximumProduct(int[] nums) {
int min1 = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE;
int max1 = Integer.MIN_VALUE, max2 = Integer.MIN_VALUE, max3 = Integer.MIN_VALUE;
for (int n: nums) {
if (n <= min1) {
min2 = min1;
min1 = n;
} else if (n <= min2) { // n lies between min1 and min2
min2 = n;
}
if (n >= max1) { // n is greater than max1, max2 and max3
max3 = max2;
max2 = max1;
max1 = n;
} else if (n >= max2) { // n lies betweeen max1 and max2
max3 = max2;
max2 = n;
} else if (n >= max3) { // n lies betwen max2 and max3
max3 = n;
}
}
return Math.max(min1 * min2 * max1, max1 * max2 * max3);
} | public int sample_funcname ( int [ ] var_0 ) {
int var_3 = Integer . MAX_VALUE , var_4 = Integer . MAX_VALUE ;
int var_6 = Integer . MIN_VALUE , var_7 = Integer . MIN_VALUE , var_8 = Integer . MIN_VALUE ;
for ( int var_9 : var_0 ) {
if ( var_9 <= var_3 ) {
var_4 = var_3 ;
var_3 = var_9 ;
}
else if ( var_9 <= var_4 ) {
var_4 = var_9 ;
}
if ( var_9 >= var_6 ) {
var_8 = var_7 ;
var_7 = var_6 ;
var_6 = var_9 ;
}
else if ( var_9 >= var_7 ) {
var_8 = var_7 ;
var_7 = var_9 ;
}
else if ( var_9 >= var_8 ) {
var_8 = var_9 ;
}
}
return Math . max ( var_3 * var_4 * var_6 , var_6 * var_7 * var_8 ) ;
}
|
50 | <qiyuangong>485_Max_Consecutive_Ones_1.java | public int findMaxConsecutiveOnes(int[] nums) {
int ans = 0;
int curr = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 1) {
curr++;
if (curr > ans) ans = curr;
} else {
curr = 0;
}
}
return ans;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 ;
int var_3 = 0 ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 ++ ) {
if ( var_0 [ var_4 ] == 1 ) {
var_3 ++ ;
if ( var_3 > var_2 ) var_2 = var_3 ;
}
else {
var_3 = 0 ;
}
}
return var_2 ;
}
|
51 | <qiyuangong>400_Nth_Digit_1.java | public int findNthDigit(int n) {
int len = 1;
long count = 9;
int start = 1;
while (n > len * count) {
n -= len * count;
len += 1;
count *= 10;
start *= 10;
}
start += (n - 1) / len;
String s = Integer.toString(start);
return Character.getNumericValue(s.charAt((n - 1) % len));
} | public int sample_funcname ( int var_0 ) {
int var_2 = 1 ;
long var_4 = 9 ;
int var_5 = 1 ;
while ( var_0 > var_2 * var_4 ) {
var_0 -= var_2 * var_4 ;
var_2 += 1 ;
var_4 *= 10 ;
var_5 *= 10 ;
}
var_5 += ( var_0 - 1 ) / var_2 ;
String var_10 = Integer . toString ( var_5 ) ;
return Character . getNumericValue ( var_10 . charAt ( ( var_0 - 1 ) % var_2 ) ) ;
}
|
52 | <qiyuangong>954_Array_of_Doubled_Pairs_1.java | public boolean canReorderDoubled(int[] A) {
HashMap<Integer, Integer> valueMap = new HashMap<>();
A = Arrays.stream(A).
boxed().
sorted((a, b) -> Integer.compare(Math.abs(a), Math.abs(b))).
mapToInt(i -> i).
toArray();
for (int n: A) valueMap.put(n, valueMap.getOrDefault(n, 0) + 1);
for (int n: A) {
if (valueMap.get(n) <= 0) continue;
if (valueMap.containsKey(2 * n) && valueMap.get(2 * n) > 0) {
valueMap.put(n, valueMap.get(n) - 1);
valueMap.put(2 * n, valueMap.get(2 * n) - 1);
} else {
return false;
}
}
return true;
} | public boolean var_0 ( int [ ] var_1 ) {
HashMap < Integer , Integer > var_4 = new HashMap < > ( ) ;
var_1 = Arrays . stream ( var_1 ) . boxed ( ) . sorted ( ( var_8 , var_6 ) -> Integer . compare ( Math . abs ( var_8 ) , Math . abs ( var_6 ) ) ) . mapToInt ( var_7 -> var_7 ) . toArray ( ) ;
for ( int var_17 : var_1 ) var_4 . put ( var_17 , var_4 . getOrDefault ( var_17 , 0 ) + 1 ) ;
for ( int var_17 : var_1 ) {
if ( var_4 . get ( var_17 ) <= 0 ) continue ;
if ( var_4 . containsKey ( 2 * var_17 ) && var_4 . get ( 2 * var_17 ) > 0 ) {
var_4 . put ( var_17 , var_4 . get ( var_17 ) - 1 ) ;
var_4 . put ( 2 * var_17 , var_4 . get ( 2 * var_17 ) - 1 ) ;
}
else {
return false ;
}
}
return true ;
}
|
53 | <qiyuangong>697_Degree_of_an_Array_1.java | public int findShortestSubArray(int[] nums) {
Map<Integer, Integer> left = new HashMap(),
right = new HashMap(), count = new HashMap();
for (int i = 0; i < nums.length; i++) {
int x = nums[i];
if (left.get(x) == null) left.put(x, i);
right.put(x, i);
count.put(x, count.getOrDefault(x, 0) + 1);
}
int ans = nums.length;
int degree = Collections.max(count.values());
for (int x: count.keySet()) {
if (count.get(x) == degree) {
ans = Math.min(ans, right.get(x) - left.get(x) + 1);
}
}
return ans;
} | public int sample_funcname ( int [ ] var_0 ) {
Map < Integer , Integer > var_4 = new HashMap ( ) , var_5 = new HashMap ( ) , var_6 = new HashMap ( ) ;
for ( int var_8 = 0 ;
var_8 < var_0 . length ;
var_8 ++ ) {
int var_10 = var_0 [ var_8 ] ;
if ( var_4 . get ( var_10 ) == null ) var_4 . put ( var_10 , var_8 ) ;
var_5 . put ( var_10 , var_8 ) ;
var_6 . put ( var_10 , var_6 . getOrDefault ( var_10 , 0 ) + 1 ) ;
}
int var_16 = var_0 . length ;
int var_20 = Collections . max ( var_6 . values ( ) ) ;
for ( int var_10 : var_6 . keySet ( ) ) {
if ( var_6 . get ( var_10 ) == var_20 ) {
var_16 = Math . min ( var_16 , var_5 . get ( var_10 ) - var_4 . get ( var_10 ) + 1 ) ;
}
}
return var_16 ;
}
|
54 | <qiyuangong>268_Missing_Number_1.java | public int missingNumber(int[] nums) {
int res = nums.length;
for (int i = 0; i < nums.length; i++) {
res ^= i;
res ^= nums[i];
}
return res;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = var_0 . length ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 ++ ) {
var_2 ^= var_4 ;
var_2 ^= var_0 [ var_4 ] ;
}
return var_2 ;
}
|
55 | <qiyuangong>605_Can_Place_Flowers_1.java | public boolean canPlaceFlowers(int[] flowerbed, int n) {
int i = 0, count = 0;
while (i < flowerbed.length) {
if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) && (i == flowerbed.length - 1 || flowerbed[i + 1] == 0)) {
flowerbed[i++] = 1;
count++;
}
if(count >= n)
return true;
i++;
}
return false;
} | public boolean var_0 ( int [ ] var_1 , int var_2 ) {
int var_4 = 0 , var_5 = 0 ;
while ( var_4 < var_1 . length ) {
if ( var_1 [ var_4 ] == 0 && ( var_4 == 0 || var_1 [ var_4 - 1 ] == 0 ) && ( var_4 == var_1 . length - 1 || var_1 [ var_4 + 1 ] == 0 ) ) {
var_1 [ var_4 ++ ] = 1 ;
var_5 ++ ;
}
if ( var_5 >= var_2 ) return true ;
var_4 ++ ;
}
return false ;
}
|
56 | <qiyuangong>867_Transpose_Matrix_1.java | public int[][] transpose(int[][] A) {
int R = A.length, C = A[0].length;
int[][] ans = new int[C][R];
for (int r = 0; r < R; ++r)
for (int c = 0; c < C; ++c) {
ans[c][r] = A[r][c];
}
return ans;
} | public int [ ] [ ] sample_funcname ( int [ ] [ ] var_0 ) {
int var_2 = var_0 . length , var_4 = var_0 [ 0 ] . length ;
int [ ] [ ] var_5 = new int [ var_4 ] [ var_2 ] ;
for ( int var_6 = 0 ;
var_6 < var_2 ;
++ var_6 ) for ( int var_7 = 0 ;
var_7 < var_4 ;
++ var_7 ) {
var_5 [ var_7 ] [ var_6 ] = var_0 [ var_6 ] [ var_7 ] ;
}
return var_5 ;
}
|
57 | <qiyuangong>946_Validate_Stack_Sequences_1.java | public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> inStack = new Stack<>();
int posPush = 0, posPop = 0;
while (posPush != pushed.length) {
int curr = pushed[posPush];
while (!inStack.empty() && popped.length > 0 && inStack.peek() == popped[posPop]) {
inStack.pop();
posPop++;
}
if (popped.length == 0) break;
if (curr == popped[posPop]) posPop++;
else inStack.push(curr);
posPush++;
}
while (!inStack.empty() && popped.length > 0 && inStack.peek() == popped[posPop]) {
inStack.pop();
posPop++;
}
if (inStack.empty()) return true;
return false;
} | public boolean var_0 ( int [ ] var_1 , int [ ] var_2 ) {
Stack < Integer > var_5 = new Stack < > ( ) ;
int var_7 = 0 , var_8 = 0 ;
while ( var_7 != var_1 . length ) {
int var_10 = var_1 [ var_7 ] ;
while ( ! var_5 . empty ( ) && var_2 . length > 0 && var_5 . peek ( ) == var_2 [ var_8 ] ) {
var_5 . pop ( ) ;
var_8 ++ ;
}
if ( var_2 . length == 0 ) break ;
if ( var_10 == var_2 [ var_8 ] ) var_8 ++ ;
else var_5 . push ( var_10 ) ;
var_7 ++ ;
}
while ( ! var_5 . empty ( ) && var_2 . length > 0 && var_5 . peek ( ) == var_2 [ var_8 ] ) {
var_5 . pop ( ) ;
var_8 ++ ;
}
if ( var_5 . empty ( ) ) return true ;
return false ;
}
|
58 | <qiyuangong>1337_The_K_Weakest_Rows_in_a_Matrix_1.java | public int[] kWeakestRows(int[][] mat, int k) {
List<Integer> res = new ArrayList<>();
int col = 0;
boolean flag = true;
while (col < mat[0].length && flag) {
for (int i = 0; i < mat.length; i++) {
if (res.contains(i)) continue;
if (mat[i][col] == 0) res.add(i);
if (res.size() == k) {
flag = false;
break;
}
}
col += 1;
}
if (flag) {
for (int i = 0; i < mat.length; i++) {
if (res.contains(i)) continue;
res.add(i);
if (res.size() == k) break;
}
}
int[] ret = new int[k];
for (int i = 0; i < k; i++) ret[i] = res.get(i);
return ret;
} | public int [ ] sample_funcname ( int [ ] [ ] var_0 , int var_1 ) {
List < Integer > var_5 = new ArrayList < > ( ) ;
int var_7 = 0 ;
boolean var_10 = true ;
while ( var_7 < var_0 [ 0 ] . length && var_10 ) {
for ( int var_11 = 0 ;
var_11 < var_0 . length ;
var_11 ++ ) {
if ( var_5 . contains ( var_11 ) ) continue ;
if ( var_0 [ var_11 ] [ var_7 ] == 0 ) var_5 . add ( var_11 ) ;
if ( var_5 . size ( ) == var_1 ) {
var_10 = false ;
break ;
}
}
var_7 += 1 ;
}
if ( var_10 ) {
for ( int var_11 = 0 ;
var_11 < var_0 . length ;
var_11 ++ ) {
if ( var_5 . contains ( var_11 ) ) continue ;
var_5 . add ( var_11 ) ;
if ( var_5 . size ( ) == var_1 ) break ;
}
}
int [ ] var_16 = new int [ var_1 ] ;
for ( int var_11 = 0 ;
var_11 < var_1 ;
var_11 ++ ) var_16 [ var_11 ] = var_5 . get ( var_11 ) ;
return var_16 ;
}
|
59 | <qiyuangong>844_Backspace_String_Compare_1.java | public boolean backspaceCompare(String S, String T) {
int i = S.length() - 1, j = T.length() - 1;
while (true) {
for (int back = 0; i >= 0 && (back > 0 || S.charAt(i) == '#'); --i)
back += S.charAt(i) == '#' ? 1 : -1;
for (int back = 0; j >= 0 && (back > 0 || T.charAt(j) == '#'); --j)
back += T.charAt(j) == '#' ? 1 : -1;
if (i >= 0 && j >= 0 && S.charAt(i) == T.charAt(j)) {
i--; j--;
} else
return i == -1 && j == -1;
}
} | public boolean var_0 ( String var_2 , String var_3 ) {
int var_6 = var_2 . length ( ) - 1 , var_7 = var_3 . length ( ) - 1 ;
while ( true ) {
for ( int var_9 = 0 ;
var_6 >= 0 && ( var_9 > 0 || var_2 . charAt ( var_6 ) == '#' ) ;
-- var_6 ) var_9 += var_2 . charAt ( var_6 ) == '#' ? 1 : - 1 ;
for ( int var_9 = 0 ;
var_7 >= 0 && ( var_9 > 0 || var_3 . charAt ( var_7 ) == '#' ) ;
-- var_7 ) var_9 += var_3 . charAt ( var_7 ) == '#' ? 1 : - 1 ;
if ( var_6 >= 0 && var_7 >= 0 && var_2 . charAt ( var_6 ) == var_3 . charAt ( var_7 ) ) {
var_6 -- ;
var_7 -- ;
}
else return var_6 == - 1 && var_7 == - 1 ;
}
}
|
60 | <qiyuangong>751_IP_to_CIDR_2.java | private String longToIP(long x) {
return String.format("%s.%s.%s.%s",
x >> 24, (x >> 16) % 256, (x >> 8) % 256, x % 256);
} | private String var_0 ( long var_1 ) {
return String . format ( "%s.%s.%s.%s" , var_1 >> 24 , ( var_1 >> 16 ) % 256 , ( var_1 >> 8 ) % 256 , var_1 % 256 ) ;
}
|
61 | <qiyuangong>409_Longest_Palindrome_1.java | public int longestPalindrome(String s) {
int[] count = new int[128];
for (char c: s.toCharArray())
count[c]++;
int ans = 0;
for (int v: count) {
ans += v / 2 * 2;
if (ans % 2 == 0 && v % 2 == 1)
ans++;
}
return ans;
} | public int sample_funcname ( String var_1 ) {
int [ ] var_3 = new int [ 128 ] ;
for ( char var_5 : var_1 . toCharArray ( ) ) var_3 [ var_5 ] ++ ;
int var_7 = 0 ;
for ( int var_8 : var_3 ) {
var_7 += var_8 / 2 * 2 ;
if ( var_7 % 2 == 0 && var_8 % 2 == 1 ) var_7 ++ ;
}
return var_7 ;
}
|
62 | <qiyuangong>463_Island_Perimeter_1.java | public int islandPerimeter(int[][] grid) {
int islands = 0, neighbours = 0;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
if (grid[i][j] == 1) {
islands++; // count islands
if (i < grid.length - 1 && grid[i + 1][j] == 1) neighbours++; // count down neighbours
if (j < grid[i].length - 1 && grid[i][j + 1] == 1) neighbours++; // count right neighbours
}
}
}
return islands * 4 - neighbours * 2;
} | public int sample_funcname ( int [ ] [ ] var_0 ) {
int var_2 = 0 , var_3 = 0 ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 ++ ) {
for ( int var_6 = 0 ;
var_6 < var_0 [ var_4 ] . length ;
var_6 ++ ) {
if ( var_0 [ var_4 ] [ var_6 ] == 1 ) {
var_2 ++ ;
if ( var_4 < var_0 . length - 1 && var_0 [ var_4 + 1 ] [ var_6 ] == 1 ) var_3 ++ ;
if ( var_6 < var_0 [ var_4 ] . length - 1 && var_0 [ var_4 ] [ var_6 + 1 ] == 1 ) var_3 ++ ;
}
}
}
return var_2 * 4 - var_3 * 2 ;
}
|
63 | <qiyuangong>836_Rectangle_Overlap_1.java | public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return !(rec1[2] <= rec2[0] || // left
rec1[3] <= rec2[1] || // bottom
rec1[0] >= rec2[2] || // right
rec1[1] >= rec2[3]); // top
} | public boolean var_0 ( int [ ] var_1 , int [ ] var_2 ) {
return ! ( var_1 [ 2 ] <= var_2 [ 0 ] || var_1 [ 3 ] <= var_2 [ 1 ] || var_1 [ 0 ] >= var_2 [ 2 ] || var_1 [ 1 ] >= var_2 [ 3 ] ) ;
}
|
64 | <qiyuangong>905_Sort_Array_By_Parity_1.java | public int[] sortArrayByParity(int[] A) {
int[] ans = new int[A.length];
int pos = 0;
for (int num: A)
if (num % 2 == 0)
ans[pos++] = num;
for (int num: A)
if (num % 2 == 1)
ans[pos++] = num;
return ans;
} | public int [ ] sample_funcname ( int [ ] var_0 ) {
int [ ] var_2 = new int [ var_0 . length ] ;
int var_4 = 0 ;
for ( int var_5 : var_0 ) if ( var_5 % 2 == 0 ) var_2 [ var_4 ++ ] = var_5 ;
for ( int var_5 : var_0 ) if ( var_5 % 2 == 1 ) var_2 [ var_4 ++ ] = var_5 ;
return var_2 ;
}
|
65 | <qiyuangong>695_Max_Area_of_Island_1.java | public int maxAreaOfIsland(int[][] grid) {
int[] dr = new int[]{1, -1, 0, 0};
int[] dc = new int[]{0, 0, 1, -1};
int ans = 0;
for (int r0 = 0; r0 < grid.length; r0++) {
for (int c0 = 0; c0 < grid[0].length; c0++) {
if (grid[r0][c0] == 1) {
int shape = 0;
Stack<int[]> stack = new Stack();
stack.push(new int[]{r0, c0});
grid[r0][c0] = 0;
while (!stack.empty()) {
int[] node = stack.pop();
int r = node[0], c = node[1];
shape++;
for (int k = 0; k < 4; k++) {
int nr = r + dr[k];
int nc = c + dc[k];
if (0 <= nr && nr < grid.length &&
0 <= nc && nc < grid[0].length &&
grid[nr][nc] == 1) {
stack.push(new int[]{nr, nc});
grid[nr][nc] = 0;
}
}
}
ans = Math.max(ans, shape);
}
}
}
return ans;
} | public int sample_funcname ( int [ ] [ ] var_0 ) {
int [ ] var_3 = new int [ ] {
1 , - 1 , 0 , 0 };
int [ ] var_4 = new int [ ] {
0 , 0 , 1 , - 1 };
int var_5 = 0 ;
for ( int var_6 = 0 ;
var_6 < var_0 . length ;
var_6 ++ ) {
for ( int var_8 = 0 ;
var_8 < var_0 [ 0 ] . length ;
var_8 ++ ) {
if ( var_0 [ var_6 ] [ var_8 ] == 1 ) {
int var_9 = 0 ;
Stack < int [ ] > var_11 = new Stack ( ) ;
var_11 . push ( new int [ ] {
var_6 , var_8 }
) ;
var_0 [ var_6 ] [ var_8 ] = 0 ;
while ( ! var_11 . empty ( ) ) {
int [ ] var_15 = var_11 . pop ( ) ;
int var_16 = var_15 [ 0 ] , var_17 = var_15 [ 1 ] ;
var_9 ++ ;
for ( int var_18 = 0 ;
var_18 < 4 ;
var_18 ++ ) {
int var_20 = var_16 + var_3 [ var_18 ] ;
int var_21 = var_17 + var_4 [ var_18 ] ;
if ( 0 <= var_20 && var_20 < var_0 . length && 0 <= var_21 && var_21 < var_0 [ 0 ] . length && var_0 [ var_20 ] [ var_21 ] == 1 ) {
var_11 . push ( new int [ ] {
var_20 , var_21 }
) ;
var_0 [ var_20 ] [ var_21 ] = 0 ;
}
}
}
var_5 = Math . max ( var_5 , var_9 ) ;
}
}
}
return var_5 ;
}
|
66 | <qiyuangong>453_Minimum_Moves_to_Equal_Array_Elements_1.java | public int minMoves(int[] nums) {
if (nums.length == 0) return 0;
Arrays.sort(nums);
int min_num = nums[0];
int ans = 0;
for (int num : nums) {
ans += num - min_num;
}
return ans;
} | public int sample_funcname ( int [ ] var_0 ) {
if ( var_0 . length == 0 ) return 0 ;
Arrays . sort ( var_0 ) ;
int var_5 = var_0 [ 0 ] ;
int var_6 = 0 ;
for ( int var_7 : var_0 ) {
var_6 += var_7 - var_5 ;
}
return var_6 ;
}
|
67 | <qiyuangong>922_Sort_Array_By_Parity_II_1.java | public int[] sortArrayByParityII(int[] A) {
int N = A.length;
int[] ans = new int[N];
int t = 0;
for (int x: A) if (x % 2 == 0) {
ans[t] = x;
t += 2;
}
t = 1;
for (int x: A) if (x % 2 == 1) {
ans[t] = x;
t += 2;
}
return ans;
} | public int [ ] sample_funcname ( int [ ] var_0 ) {
int var_2 = var_0 . length ;
int [ ] var_3 = new int [ var_2 ] ;
int var_5 = 0 ;
for ( int var_6 : var_0 ) if ( var_6 % 2 == 0 ) {
var_3 [ var_5 ] = var_6 ;
var_5 += 2 ;
}
var_5 = 1 ;
for ( int var_6 : var_0 ) if ( var_6 % 2 == 1 ) {
var_3 [ var_5 ] = var_6 ;
var_5 += 2 ;
}
return var_3 ;
}
|
68 | <qiyuangong>482_License_Key_Formatting_1.java | public String licenseKeyFormatting(String s, int k) {
StringBuilder sb = new StringBuilder();
for (int i = s.length() - 1; i >= 0; i--)
if (s.charAt(i) != '-')
sb.append(sb.length() % (k + 1) == k ? '-' : "").append(s.charAt(i));
return sb.reverse().toString().toUpperCase();
} | public String var_0 ( String var_2 , int var_3 ) {
StringBuilder var_5 = new StringBuilder ( ) ;
for ( int var_8 = var_2 . length ( ) - 1 ;
var_8 >= 0 ;
var_8 -- ) if ( var_2 . charAt ( var_8 ) != '-' ) var_5 . append ( var_5 . length ( ) % ( var_3 + 1 ) == var_3 ? '-' : "" ) . append ( var_2 . charAt ( var_8 ) ) ;
return var_5 . reverse ( ) . toString ( ) . toUpperCase ( ) ;
}
|
69 | <qiyuangong>1260_Shift_2D_Grid_1.java | public List<List<Integer>> shiftGrid(int[][] grid, int k) {
int[][] newGrid = new int[grid.length][grid[0].length];
int m = grid.length;
int n = grid[0].length;
int true_k = k % (m * n);
int move_i = true_k / n;
int move_j = true_k % n;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
int new_i = i + move_i;
int new_j = (j + move_j) % n;
if (move_j + j >= n) new_i ++;
new_i %= m;
newGrid[new_i][new_j] = grid[i][j];
}
}
List<List<Integer>> result = new ArrayList<>();
for (int[] row : newGrid) {
List<Integer> listRow = new ArrayList<>();
result.add(listRow);
for (int v : row) listRow.add(v);
}
return result;
} | public List < List < Integer >> var_2 ( int [ ] [ ] var_3 , int var_4 ) {
int [ ] [ ] var_7 = new int [ var_3 . length ] [ var_3 [ 0 ] . length ] ;
int var_8 = var_3 . length ;
int var_9 = var_3 [ 0 ] . length ;
int var_10 = var_4 % ( var_8 * var_9 ) ;
int var_11 = var_10 / var_9 ;
int var_12 = var_10 % var_9 ;
for ( int var_13 = 0 ;
var_13 < var_3 . length ;
var_13 ++ ) {
for ( int var_14 = 0 ;
var_14 < var_3 [ var_13 ] . length ;
var_14 ++ ) {
int var_15 = var_13 + var_11 ;
int var_16 = ( var_14 + var_12 ) % var_9 ;
if ( var_12 + var_14 >= var_9 ) var_15 ++ ;
var_15 %= var_8 ;
var_7 [ var_15 ] [ var_16 ] = var_3 [ var_13 ] [ var_14 ] ;
}
}
List < List < Integer >> var_18 = new ArrayList < > ( ) ;
for ( int [ ] var_19 : var_7 ) {
List < Integer > var_20 = new ArrayList < > ( ) ;
var_18 . add ( var_20 ) ;
for ( int var_22 : var_19 ) var_20 . add ( var_22 ) ;
}
return var_18 ;
}
|
70 | <qiyuangong>836_Rectangle_Overlap_2.java | public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
int left = Math.max(rec1[0], rec2[0]), right = Math.max(Math.min(rec1[2], rec2[2]), left);
int bottom = Math.max(rec1[1], rec2[1]), top = Math.max(Math.min(rec1[3], rec2[3]), bottom);
return (right - left) * (top - bottom) != 0;
} | public boolean var_0 ( int [ ] var_1 , int [ ] var_2 ) {
int var_6 = Math . max ( var_1 [ 0 ] , var_2 [ 0 ] ) , var_9 = Math . max ( Math . min ( var_1 [ 2 ] , var_2 [ 2 ] ) , var_6 ) ;
int var_11 = Math . max ( var_1 [ 1 ] , var_2 [ 1 ] ) , var_13 = Math . max ( Math . min ( var_1 [ 3 ] , var_2 [ 3 ] ) , var_11 ) ;
return ( var_9 - var_6 ) * ( var_13 - var_11 ) != 0 ;
}
|
71 | <qiyuangong>905_Sort_Array_By_Parity_2.java | public int[] sortArrayByParity(int[] A) {
int lo = 0, hi = A.length - 1;
while (lo < hi) {
if (A[lo] % 2 > A[hi] % 2) {
int tmp = A[hi];
A[hi] = A[lo];
A[lo] = tmp;
}
if (A[lo] % 2 == 0) lo++;
if (A[hi] % 2 == 1) hi--;
}
return A;
} | public int [ ] sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 , var_5 = var_0 . length - 1 ;
while ( var_2 < var_5 ) {
if ( var_0 [ var_2 ] % 2 > var_0 [ var_5 ] % 2 ) {
int var_7 = var_0 [ var_5 ] ;
var_0 [ var_5 ] = var_0 [ var_2 ] ;
var_0 [ var_2 ] = var_7 ;
}
if ( var_0 [ var_2 ] % 2 == 0 ) var_2 ++ ;
if ( var_0 [ var_5 ] % 2 == 1 ) var_5 -- ;
}
return var_0 ;
}
|
72 | <qiyuangong>922_Sort_Array_By_Parity_II_2.java | public int[] sortArrayByParityII(int[] A) {
int j = 1;
for (int i = 0; i < A.length; i += 2)
if (A[i] % 2 == 1) {
while (A[j] % 2 == 1)
j += 2;
int tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
return A;
} | public int [ ] sample_funcname ( int [ ] var_0 ) {
int var_2 = 1 ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 += 2 ) if ( var_0 [ var_4 ] % 2 == 1 ) {
while ( var_0 [ var_2 ] % 2 == 1 ) var_2 += 2 ;
int var_7 = var_0 [ var_4 ] ;
var_0 [ var_4 ] = var_0 [ var_2 ] ;
var_0 [ var_2 ] = var_7 ;
}
return var_0 ;
}
|
73 | <qiyuangong>868_Binary_Gap_1.java | public int binaryGap(int N) {
int last = -1, ans = 0;
for (int i = 0; i < 32; ++i)
if (((N >> i) & 1) > 0) {
if (last >= 0)
ans = Math.max(ans, i - last);
last = i;
}
return ans;
} | public int sample_funcname ( int var_0 ) {
int var_2 = - 1 , var_4 = 0 ;
for ( int var_5 = 0 ;
var_5 < 32 ;
++ var_5 ) if ( ( ( var_0 >> var_5 ) & 1 ) > 0 ) {
if ( var_2 >= 0 ) var_4 = Math . max ( var_4 , var_5 - var_2 ) ;
var_2 = var_5 ;
}
return var_4 ;
}
|
74 | <qiyuangong>605_Can_Place_Flowers_2.java | public boolean canPlaceFlowers(int[] flowerbed, int n) {
int count = 0, curr;
for (int i = 0; i < flowerbed.length; i++) {
curr = flowerbed[i];
if (i - 1 >= 0) curr += flowerbed[i - 1];
if (i + 1 < flowerbed.length) curr += flowerbed[i + 1];
if (curr == 0) {
count++;
flowerbed[i] = 1;
}
if (count >= n) return true;
}
return false;
} | public boolean var_0 ( int [ ] var_1 , int var_2 ) {
int var_4 = 0 , var_5 ;
for ( int var_6 = 0 ;
var_6 < var_1 . length ;
var_6 ++ ) {
var_5 = var_1 [ var_6 ] ;
if ( var_6 - 1 >= 0 ) var_5 += var_1 [ var_6 - 1 ] ;
if ( var_6 + 1 < var_1 . length ) var_5 += var_1 [ var_6 + 1 ] ;
if ( var_5 == 0 ) {
var_4 ++ ;
var_1 [ var_6 ] = 1 ;
}
if ( var_4 >= var_2 ) return true ;
}
return false ;
}
|
75 | <qiyuangong>389_Find_the_Difference_1.java | public char findTheDifference(String s, String t) {
int total = t.charAt(s.length());
for (int i = 0; i < s.length(); i++)
total += (t.charAt(i) - s.charAt(i));
return (char) total;
} | public char sample_funcname ( String var_1 , String var_2 ) {
int var_5 = var_2 . charAt ( var_1 . length ( ) ) ;
for ( int var_7 = 0 ;
var_7 < var_1 . length ( ) ;
var_7 ++ ) var_5 += ( var_2 . charAt ( var_7 ) - var_1 . charAt ( var_7 ) ) ;
return ( char ) var_5 ;
}
|
76 | <qiyuangong>401_Binary_Watch_1.java | public List<String> readBinaryWatch(int num) {
List<String> times = new ArrayList<>();
for (int h = 0; h < 12; h++)
for (int m = 0; m < 60; m++)
if (Integer.bitCount(h * 64 + m) == num)
times.add(String.format("%d:%02d", h, m));
return times;
} | public List < String > var_1 ( int var_2 ) {
List < String > var_5 = new ArrayList < > ( ) ;
for ( int var_7 = 0 ;
var_7 < 12 ;
var_7 ++ ) for ( int var_9 = 0 ;
var_9 < 60 ;
var_9 ++ ) if ( Integer . bitCount ( var_7 * 64 + var_9 ) == var_2 ) var_5 . add ( String . format ( "%d:%02d" , var_7 , var_9 ) ) ;
return var_5 ;
}
|
77 | <qiyuangong>383_Ransom_Note_1.java | public boolean canConstruct(String ransomNote, String magazine) {
int[] table = new int[128];
for (char c : magazine.toCharArray()) table[c]++;
for (char c : ransomNote.toCharArray())
if (--table[c] < 0) return false;
return true;
} | public boolean var_0 ( String var_2 , String var_3 ) {
int [ ] var_5 = new int [ 128 ] ;
for ( char var_7 : var_3 . toCharArray ( ) ) var_5 [ var_7 ] ++ ;
for ( char var_7 : var_2 . toCharArray ( ) ) if ( -- var_5 [ var_7 ] < 0 ) return false ;
return true ;
}
|
78 | <qiyuangong>844_Backspace_String_Compare_2.java | private String trans(String str) {
StringBuilder sb = new StringBuilder();
for (char c : str.toCharArray()) {
if (c != '#') { sb.append(c); } // if not '#', append it at the end of sb.
else if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } // remove last char in sb, if sb is not empty.
}
return sb.toString();
} | private String var_0 ( String var_2 ) {
StringBuilder var_4 = new StringBuilder ( ) ;
for ( char var_6 : var_2 . toCharArray ( ) ) {
if ( var_6 != '#' ) {
var_4 . append ( var_6 ) ;
}
else if ( var_4 . length ( ) > 0 ) {
var_4 . deleteCharAt ( var_4 . length ( ) - 1 ) ;
}
}
return var_4 . toString ( ) ;
}
|
79 | <qiyuangong>751_IP_to_CIDR_1.java | private long ipToLong(String ip) {
long ans = 0;
for (String x: ip.split("\\.")) {
ans = 256 * ans + Integer.valueOf(x);
}
return ans;
} | private long sample_funcname ( String var_1 ) {
long var_3 = 0 ;
for ( String var_6 : var_1 . split ( "\\." ) ) {
var_3 = 256 * var_3 + Integer . valueOf ( var_6 ) ;
}
return var_3 ;
}
|
80 | <qiyuangong>1310_XOR_Queries_of_a_Subarray_1.java | public int[] xorQueries(int[] arr, int[][] queries) {
int[] res = new int[queries.length], q;
for (int i = 1; i < arr.length; i++)
arr[i] ^= arr[i - 1];
for (int i = 0; i < queries.length; i++) {
q = queries[i];
res[i] = q[0] > 0 ? arr[q[0] - 1] ^ arr[q[1]] : arr[q[1]];
}
return res;
} | public int [ ] sample_funcname ( int [ ] var_0 , int [ ] [ ] var_1 ) {
int [ ] var_3 = new int [ var_1 . length ] , var_4 ;
for ( int var_6 = 1 ;
var_6 < var_0 . length ;
var_6 ++ ) var_0 [ var_6 ] ^= var_0 [ var_6 - 1 ] ;
for ( int var_6 = 0 ;
var_6 < var_1 . length ;
var_6 ++ ) {
var_4 = var_1 [ var_6 ] ;
var_3 [ var_6 ] = var_4 [ 0 ] > 0 ? var_0 [ var_4 [ 0 ] - 1 ] ^ var_0 [ var_4 [ 1 ] ] : var_0 [ var_4 [ 1 ] ] ;
}
return var_3 ;
}
|
81 | <qiyuangong>443_String_Compression_1.java | public int compress(char[] chars) {
int anchor = 0, write = 0;
for (int read = 0; read < chars.length; read++) {
if (read + 1 == chars.length || chars[read + 1] != chars[read]) {
chars[write++] = chars[anchor];
if (read > anchor) {
for (char c: ("" + (read - anchor + 1)).toCharArray()) {
chars[write++] = c;
}
}
anchor = read + 1;
}
}
return write;
} | public int sample_funcname ( char [ ] var_0 ) {
int var_2 = 0 , var_3 = 0 ;
for ( int var_4 = 0 ;
var_4 < var_0 . length ;
var_4 ++ ) {
if ( var_4 + 1 == var_0 . length || var_0 [ var_4 + 1 ] != var_0 [ var_4 ] ) {
var_0 [ var_3 ++ ] = var_0 [ var_2 ] ;
if ( var_4 > var_2 ) {
for ( char var_9 : ( "" + ( var_4 - var_2 + 1 ) ) . toCharArray ( ) ) {
var_0 [ var_3 ++ ] = var_9 ;
}
}
var_2 = var_4 + 1 ;
}
}
return var_3 ;
}
|
82 | <qiyuangong>557_Reverse_Words_in_a_String_III_1.java | public String reverseWords(String s) {
String words[] = s.split(" ");
StringBuilder ans = new StringBuilder();
for (String word: words)
ans.append(new StringBuffer(word).reverse().toString() + " ");
return ans.toString().trim();
} | public String var_0 ( String var_2 ) {
String var_5 [ ] = var_2 . split ( " " ) ;
StringBuilder var_7 = new StringBuilder ( ) ;
for ( String var_8 : var_5 ) var_7 . append ( new StringBuffer ( var_8 ) . reverse ( ) . toString ( ) + " " ) ;
return var_7 . toString ( ) . trim ( ) ;
}
|
83 | <qiyuangong>509_Fibonacci_Number_1.java | public int fib(int N) {
if (N == 0) return 0;
if (N == 1) return 1;
return fib(N - 1) + fib(N - 2);
} | public int sample_funcname ( int N ) {
if ( N == 0 ) return 0 ;
if ( N == 1 ) return 1 ;
return fib ( N - 1 ) + fib ( N - 2 ) ;
}
|
84 | <qiyuangong>628_Maximum_Product_of_Three_Numbers_1.java | public int maximumProduct(int[] nums) {
Arrays.sort(nums);
return Math.max(nums[0] * nums[1] * nums[nums.length - 1], nums[nums.length - 1] * nums[nums.length - 2] * nums[nums.length - 3]);
} | public int sample_funcname ( int [ ] var_0 ) {
Arrays . sort ( var_0 ) ;
return Math . max ( var_0 [ 0 ] * var_0 [ 1 ] * var_0 [ var_0 . length - 1 ] , var_0 [ var_0 . length - 1 ] * var_0 [ var_0 . length - 2 ] * var_0 [ var_0 . length - 3 ] ) ;
}
|
85 | <qiyuangong>367_Valid_Perfect_Square_1.java | public boolean isPerfectSquare(int num) {
int low = 1;
int high = num;
while (low <= high) {
long mid = (low + high) >>> 1;
if (mid * mid == num) {
return true;
} else if (mid * mid < num) {
low = (int) mid + 1;
} else {
high = (int) mid - 1;
}
}
return false;
} | public boolean var_0 ( int var_1 ) {
int var_3 = 1 ;
int var_4 = var_1 ;
while ( var_3 <= var_4 ) {
long var_5 = ( var_3 + var_4 ) >>> 1 ;
if ( var_5 * var_5 == var_1 ) {
return true ;
}
else if ( var_5 * var_5 < var_1 ) {
var_3 = ( int ) var_5 + 1 ;
}
else {
var_4 = ( int ) var_5 - 1 ;
}
}
return false ;
}
|
86 | <qiyuangong>832_Flipping_an_Image_1.java | public int[][] flipAndInvertImage(int[][] A) {
int C = A[0].length;
for (int[] row: A)
for (int i = 0; i < (C + 1) / 2; ++i) {
int tmp = row[i] ^ 1;
row[i] = row[C - 1 - i] ^ 1;
row[C - 1 - i] = tmp;
}
return A;
} | public int [ ] [ ] sample_funcname ( int [ ] [ ] var_0 ) {
int var_3 = var_0 [ 0 ] . length ;
for ( int [ ] var_4 : var_0 ) for ( int var_5 = 0 ;
var_5 < ( var_3 + 1 ) / 2 ;
++ var_5 ) {
int var_8 = var_4 [ var_5 ] ^ 1 ;
var_4 [ var_5 ] = var_4 [ var_3 - 1 - var_5 ] ^ 1 ;
var_4 [ var_3 - 1 - var_5 ] = var_8 ;
}
return var_0 ;
}
|
87 | <qiyuangong>336_Palindrome_Pairs_1.java | private boolean isPalindrome(String word, int i, int j) {
while (i < j) {
if (word.charAt(i++) != word.charAt(j--)) return false;
}
return true;
} | private boolean var_0 ( String var_2 , int var_3 , int var_4 ) {
while ( var_3 < var_4 ) {
if ( var_2 . charAt ( var_3 ++ ) != var_2 . charAt ( var_4 -- ) ) return false ;
}
return true ;
}
|
88 | <qiyuangong>962_Maximum_Width_Ramp_2.java | public int maxWidthRamp(int[] A) {
int N = A.length;
int ans = 0;
List<Point> candidates = new ArrayList();
candidates.add(new Point(A[N-1], N-1));
for (int i = N-2; i >= 0; --i) {
int lo = 0, hi = candidates.size();
while (lo < hi) {
int mi = lo + (hi - lo) / 2;
if (candidates.get(mi).x < A[i])
lo = mi + 1;
else
hi = mi;
}
if (lo < candidates.size()) {
int j = candidates.get(lo).y;
ans = Math.max(ans, j - i);
} else {
candidates.add(new Point(A[i], i));
}
}
return ans;
} | public int sample_funcname ( int [ ] A ) {
int N = A . length ;
int ans = 0 ;
List < Point > candidates = new ArrayList ( ) ;
candidates . add ( new Point ( A [ N - 1 ] , N - 1 ) ) ;
for ( int i = N - 2 ;
i >= 0 ;
-- i ) {
int lo = 0 , hi = candidates . size ( ) ;
while ( lo < hi ) {
int mi = lo + ( hi - lo ) / 2 ;
if ( candidates . get ( mi ) . x < A [ i ] ) lo = mi + 1 ;
else hi = mi ;
}
if ( lo < candidates . size ( ) ) {
int j = candidates . get ( lo ) . y ;
ans = Math . max ( ans , j - i ) ;
}
else {
candidates . add ( new Point ( A [ i ] , i ) ) ;
}
}
return ans ;
}
|
89 | <qiyuangong>674_Longest_Continuous_Increasing_Subsequence_1.java | public int findLengthOfLCIS(int[] nums) {
if (nums.length == 0) return 0;
int curr = 1, ans = 1;
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] < nums[i + 1]) {
curr ++;
if (curr >= ans) ans = curr;
} else {
curr = 1;
}
}
return ans;
} | public int sample_funcname ( int [ ] var_0 ) {
if ( var_0 . length == 0 ) return 0 ;
int var_4 = 1 , var_5 = 1 ;
for ( int var_6 = 0 ;
var_6 < var_0 . length - 1 ;
var_6 ++ ) {
if ( var_0 [ var_6 ] < var_0 [ var_6 + 1 ] ) {
var_4 ++ ;
if ( var_4 >= var_5 ) var_5 = var_4 ;
}
else {
var_4 = 1 ;
}
}
return var_5 ;
}
|
90 | <qiyuangong>852_Peak_Index_in_a_Mountain_Array_1.java | public int peakIndexInMountainArray(int[] A) {
int i = 0;
for (; A[i] < A[i + 1]; i++);
return i;
} | public int sample_funcname ( int [ ] var_0 ) {
int var_2 = 0 ;
for ( ;
var_0 [ var_2 ] < var_0 [ var_2 + 1 ] ;
var_2 ++ ) ;
return var_2 ;
}
|
91 | <qiyuangong>836_Rectangle_Overlap_3.java | public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return (Math.min(rec1[2], rec2[2]) > Math.max(rec1[0], rec2[0]) && // width > 0
Math.min(rec1[3], rec2[3]) > Math.max(rec1[1], rec2[1])); // height > 0
} | public boolean var_0 ( int [ ] var_1 , int [ ] var_2 ) {
return ( Math . min ( var_1 [ 2 ] , var_2 [ 2 ] ) > Math . max ( var_1 [ 0 ] , var_2 [ 0 ] ) && Math . min ( var_1 [ 3 ] , var_2 [ 3 ] ) > Math . max ( var_1 [ 1 ] , var_2 [ 1 ] ) ) ;
}
|
92 | <qiyuangong>215_Kth_Largest_Element_in_an_Array_2.java | private boolean less(int v, int w) {
return v < w;
} | private boolean var_0 ( int var_1 , int var_2 ) {
return var_1 < var_2 ;
}
|
93 | <qiyuangong>475_Heaters_1.java | public int findRadius(int[] houses, int[] heaters) {
Arrays.sort(heaters);
int result = Integer.MIN_VALUE;
for (int house : houses) {
int index = Arrays.binarySearch(heaters, house);
if (index < 0) index = -(index + 1);
int dist1 = index - 1 >= 0 ? house - heaters[index - 1] : Integer.MAX_VALUE;
int dist2 = index < heaters.length ? heaters[index] - house : Integer.MAX_VALUE;
result = Math.max(result, Math.min(dist1, dist2));
}
return result;
} | public int sample_funcname ( int [ ] var_0 , int [ ] var_1 ) {
Arrays . sort ( var_1 ) ;
int var_6 = Integer . MIN_VALUE ;
for ( int var_7 : var_0 ) {
int var_9 = Arrays . binarySearch ( var_1 , var_7 ) ;
if ( var_9 < 0 ) var_9 = - ( var_9 + 1 ) ;
int var_13 = var_9 - 1 >= 0 ? var_7 - var_1 [ var_9 - 1 ] : Integer . MAX_VALUE ;
int var_15 = var_9 < var_1 . length ? var_1 [ var_9 ] - var_7 : Integer . MAX_VALUE ;
var_6 = Math . max ( var_6 , Math . min ( var_13 , var_15 ) ) ;
}
return var_6 ;
}
|
94 | <qiyuangong>009_Palindrome_Number_2.java | public boolean isPalindrome(int x) {
if (x < 0) return false;
int div = 1;
while ( x / div >= 10) {
div *= 10;
}
while (x !=0) {
int l = x / div;
int r = x % 10;
if (l != r) return false;
x = (x % div) / 10;
div /= 100;
}
return true;
} | public boolean var_0 ( int var_1 ) {
if ( var_1 < 0 ) return false ;
int var_4 = 1 ;
while ( var_1 / var_4 >= 10 ) {
var_4 *= 10 ;
}
while ( var_1 != 0 ) {
int var_6 = var_1 / var_4 ;
int var_7 = var_1 % 10 ;
if ( var_6 != var_7 ) return false ;
var_1 = ( var_1 % var_4 ) / 10 ;
var_4 /= 100 ;
}
return true ;
}
|
95 | <qiyuangong>717_1-bit_and_2-bit_Characters_1.java | public boolean isOneBitCharacter(int[] bits) {
int pos = 0;
while (pos < bits.length - 1) {
pos += bits[pos] + 1;
}
return pos == bits.length - 1;
} | public boolean var_0 ( int [ ] var_1 ) {
int var_3 = 0 ;
while ( var_3 < var_1 . length - 1 ) {
var_3 += var_1 [ var_3 ] + 1 ;
}
return var_3 == var_1 . length - 1 ;
}
|
96 | <qiyuangong>541_Reverse_String_II_1.java | public String reverseStr(String s, int k) {
char[] a = s.toCharArray();
for (int start = 0; start < a.length; start += 2 * k) {
int i = start, j = Math.min(start + k - 1, a.length - 1);
while (i < j) {
char tmp = a[i];
a[i++] = a[j];
a[j--] = tmp;
}
}
return new String(a);
} | public String var_0 ( String var_2 , int var_3 ) {
char [ ] var_5 = var_2 . toCharArray ( ) ;
for ( int var_7 = 0 ;
var_7 < var_5 . length ;
var_7 += 2 * var_3 ) {
int var_10 = var_7 , var_14 = Math . min ( var_7 + var_3 - 1 , var_5 . length - 1 ) ;
while ( var_10 < var_14 ) {
char var_15 = var_5 [ var_10 ] ;
var_5 [ var_10 ++ ] = var_5 [ var_14 ] ;
var_5 [ var_14 -- ] = var_15 ;
}
}
return new String ( var_5 ) ;
}
|
97 | <qiyuangong>709_To_Lower_Case_1.java | public String toLowerCase(String str) {
return str.toLowerCase();
} | public String var_0 ( String var_2 ) {
return var_2 . toLowerCase ( ) ;
}
|
98 | <qiyuangong>819_Most_Common_Word_1.java | public String mostCommonWord(String paragraph, String[] banned) {
paragraph += ".";
Set<String> banset = new HashSet();
for (String word: banned) banset.add(word);
Map<String, Integer> count = new HashMap();
String ans = "";
int ansfreq = 0;
StringBuilder word = new StringBuilder();
for (char c: paragraph.toCharArray()) {
if (Character.isLetter(c)) {
word.append(Character.toLowerCase(c));
} else if (word.length() > 0) {
String finalword = word.toString();
if (!banset.contains(finalword)) {
count.put(finalword, count.getOrDefault(finalword, 0) + 1);
if (count.get(finalword) > ansfreq) {
ans = finalword;
ansfreq = count.get(finalword);
}
}
word = new StringBuilder();
}
}
return ans;
} | public String var_0 ( String var_2 , String [ ] var_3 ) {
var_2 += "." ;
Set < String > var_7 = new HashSet ( ) ;
for ( String var_8 : var_3 ) var_7 . add ( var_8 ) ;
Map < String , Integer > var_13 = new HashMap ( ) ;
String var_15 = "" ;
int var_17 = 0 ;
StringBuilder var_8 = new StringBuilder ( ) ;
for ( char var_20 : var_2 . toCharArray ( ) ) {
if ( Character . isLetter ( var_20 ) ) {
var_8 . append ( Character . toLowerCase ( var_20 ) ) ;
}
else if ( var_8 . length ( ) > 0 ) {
String var_27 = var_8 . toString ( ) ;
if ( ! var_7 . contains ( var_27 ) ) {
var_13 . put ( var_27 , var_13 . getOrDefault ( var_27 , 0 ) + 1 ) ;
if ( var_13 . get ( var_27 ) > var_17 ) {
var_15 = var_27 ;
var_17 = var_13 . get ( var_27 ) ;
}
}
var_8 = new StringBuilder ( ) ;
}
}
return var_15 ;
}
|
99 | <qiyuangong>1304_Find_N_Unique_Integers_Sum_up_to_Zero_1.java | public int[] sumZero(int n) {
int[] res = new int[n];
for (int i = 1; i < n; i++) {
res[i] = i;
res[0] -= i;
}
return res;
} | public int [ ] sample_funcname ( int var_0 ) {
int [ ] var_1 = new int [ var_0 ] ;
for ( int var_3 = 1 ;
var_3 < var_0 ;
var_3 ++ ) {
var_1 [ var_3 ] = var_3 ;
var_1 [ 0 ] -= var_3 ;
}
return var_1 ;
}
|
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 8