Refactor Code Style (#4151)

This commit is contained in:
Saurabh Rahate
2023-04-15 13:55:54 +05:30
committed by GitHub
parent 1ce907625b
commit 1dc388653a
100 changed files with 293 additions and 319 deletions

View File

@ -50,8 +50,8 @@ public class Anagrams {
if (s.length() != t.length()) {
return false;
} else {
char c[] = s.toCharArray();
char d[] = t.toCharArray();
char[] c = s.toCharArray();
char[] d = t.toCharArray();
Arrays.sort(c);
Arrays.sort(
d
@ -65,8 +65,8 @@ public class Anagrams {
if (a.length() != b.length()) {
return false;
} else {
int m[] = new int[26];
int n[] = new int[26];
int[] m = new int[26];
int[] n = new int[26];
for (char c : a.toCharArray()) {
m[c - 'a']++;
}
@ -90,8 +90,8 @@ public class Anagrams {
}
// this is similar to approach number 2 but here the string is not converted to character array
else {
int a[] = new int[26];
int b[] = new int[26];
int[] a = new int[26];
int[] b = new int[26];
int k = s.length();
for (int i = 0; i < k; i++) {
a[s.charAt(i) - 'a']++;

View File

@ -44,7 +44,7 @@ public class LetterCombinationsOfPhoneNumber {
// Driver code
public static void main(String[] args) {
int number[] = { 2, 3, 4 };
int[] number = { 2, 3, 4 };
printWords(number);
}
}

View File

@ -22,18 +22,8 @@ public static int myAtoi(String s) {
number = "0";
break;
}
switch (ch) {
case '0' -> number += ch;
case '1' -> number += ch;
case '2' -> number += ch;
case '3' -> number += ch;
case '4' -> number += ch;
case '5' -> number += ch;
case '6' -> number += ch;
case '7' -> number += ch;
case '8' -> number += ch;
case '9' -> number += ch;
}
if(ch >= '0' && ch <= '9')
number += ch;
} else if (ch == '-' && !isDigit) {
number += "0";
negative = true;

View File

@ -48,10 +48,7 @@ class WordLadder {
* if the endword is there. Otherwise, will return the length as 0.
*/
public static int ladderLength(String beginWord, String endWord, List<String> wordList) {
HashSet<String> set = new HashSet();
for (String word : wordList) {
set.add(word);
}
HashSet<String> set = new HashSet(wordList);
if (!set.contains(endWord)) {
return 0;