mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 04:20:16 +08:00
style: enable NeedBraces
in checkstyle (#5227)
* enable style NeedBraces * style: enable NeedBraces in checkstyle --------- Co-authored-by: Samuel Facchinello <samuel.facchinello@piksel.com>
This commit is contained in:

committed by
GitHub

parent
51fcc66345
commit
87b17e0571
@ -96,7 +96,9 @@ public class Anagrams {
|
||||
b[t.charAt(i) - 'a']++;
|
||||
}
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (a[i] != b[i]) return false;
|
||||
if (a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -16,20 +16,21 @@ final class LongestNonRepeativeSubstring {
|
||||
char temp = s.charAt(i);
|
||||
|
||||
// adding key to map if not present
|
||||
if (!map.containsKey(temp)) map.put(temp, 0);
|
||||
// checking if the first value is the dublicate value
|
||||
else if (s.charAt(start) == temp)
|
||||
if (!map.containsKey(temp)) {
|
||||
map.put(temp, 0);
|
||||
} else if (s.charAt(start) == temp) {
|
||||
start++;
|
||||
// checking if the previous value is dublicate value
|
||||
else if (s.charAt(i - 1) == temp) {
|
||||
if (max < map.size()) max = map.size();
|
||||
} else if (s.charAt(i - 1) == temp) {
|
||||
if (max < map.size()) {
|
||||
max = map.size();
|
||||
}
|
||||
map = new HashMap<>();
|
||||
start = i;
|
||||
i--;
|
||||
}
|
||||
// last possible place where dublicate value can be is between start and i
|
||||
else {
|
||||
if (max < map.size()) max = map.size();
|
||||
} else {
|
||||
if (max < map.size()) {
|
||||
max = map.size();
|
||||
}
|
||||
while (s.charAt(start) != temp) {
|
||||
map.remove(s.charAt(start));
|
||||
start++;
|
||||
@ -39,7 +40,9 @@ final class LongestNonRepeativeSubstring {
|
||||
|
||||
i++;
|
||||
}
|
||||
if (max < map.size()) max = map.size();
|
||||
if (max < map.size()) {
|
||||
max = map.size();
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ public final class MyAtoi {
|
||||
number = "0";
|
||||
break;
|
||||
}
|
||||
if (ch >= '0' && ch <= '9') number += ch;
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
number += ch;
|
||||
}
|
||||
} else if (ch == '-' && !isDigit) {
|
||||
number += "0";
|
||||
negative = true;
|
||||
|
@ -29,8 +29,11 @@ public final class Pangram {
|
||||
public static boolean isPangramUsingSet(String s) {
|
||||
HashSet<Character> alpha = new HashSet<>();
|
||||
s = s.trim().toLowerCase();
|
||||
for (int i = 0; i < s.length(); i++)
|
||||
if (s.charAt(i) != ' ') alpha.add(s.charAt(i));
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (s.charAt(i) != ' ') {
|
||||
alpha.add(s.charAt(i));
|
||||
}
|
||||
}
|
||||
return alpha.size() == 26;
|
||||
}
|
||||
|
||||
|
@ -18,13 +18,19 @@ public final class ValidParentheses {
|
||||
stack[head++] = c;
|
||||
break;
|
||||
case '}':
|
||||
if (head == 0 || stack[--head] != '{') return false;
|
||||
if (head == 0 || stack[--head] != '{') {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ')':
|
||||
if (head == 0 || stack[--head] != '(') return false;
|
||||
if (head == 0 || stack[--head] != '(') {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ']':
|
||||
if (head == 0 || stack[--head] != '[') return false;
|
||||
if (head == 0 || stack[--head] != '[') {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected character: " + c);
|
||||
|
@ -5,7 +5,9 @@ final class ZigZagPattern {
|
||||
}
|
||||
|
||||
public static String encode(String s, int numRows) {
|
||||
if (numRows < 2 || s.length() < numRows) return s;
|
||||
if (numRows < 2 || s.length() < numRows) {
|
||||
return s;
|
||||
}
|
||||
int start = 0;
|
||||
int index = 0;
|
||||
int height = 1;
|
||||
@ -18,11 +20,11 @@ final class ZigZagPattern {
|
||||
boolean bool = true;
|
||||
while (pointer < s.length()) {
|
||||
zigZagedArray[index++] = s.charAt(pointer);
|
||||
if (heightSpace == 0)
|
||||
if (heightSpace == 0) {
|
||||
pointer += depthSpace;
|
||||
else if (depthSpace == 0)
|
||||
} else if (depthSpace == 0) {
|
||||
pointer += heightSpace;
|
||||
else if (bool) {
|
||||
} else if (bool) {
|
||||
pointer += depthSpace;
|
||||
bool = false;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user