Skip to content

Fixed SonarQube warnings #1879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Solution {
public int myAtoi(String str) {
if (str == null || str.length() == 0) {
if (str == null || str.isEmpty()) {
return 0;
}
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public String longestCommonPrefix(String[] strs) {
String temp = strs[0];
int i = 1;
String cur;
while (temp.length() > 0 && i < strs.length) {
while (!temp.isEmpty() && i < strs.length) {
if (temp.length() > strs[i].length()) {
temp = temp.substring(0, strs[i].length());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/g0001_0100/s0065_valid_number/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Solution {
public boolean isNumber(String s) {
if (s == null || s.length() == 0) {
if (s == null || s.isEmpty()) {
return false;
}
boolean eSeen = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Solution {
public List<String> addOperators(String num, int target) {
List<String> res = new ArrayList<>();
if (num.length() == 0 || Long.parseLong(num) > Integer.MAX_VALUE) {
if (num.isEmpty() || Long.parseLong(num) > Integer.MAX_VALUE) {
return res;
}
char[] list = num.toCharArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
public class Solution {
public int countSegments(String s) {
s = s.trim();
if (s.length() == 0) {
if (s.isEmpty()) {
return 0;
}
String[] splitted = s.split(" ");
int result = 0;
for (String value : splitted) {
if (value.length() > 0) {
if (!value.isEmpty()) {
result++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Solution {
private static final String NEITHER = "Neither";

public String validIPAddress(String ip) {
if (ip.length() == 0) {
if (ip.isEmpty()) {
return NEITHER;
}
String[] arr = ip.split("\\.", -1);
Expand All @@ -24,7 +24,7 @@ public String validIPAddress(String ip) {
return "IPv4";
} else if (arr1.length == 8) {
for (String num : arr1) {
if (num.length() < 1 || num.length() > 4) {
if (num.isEmpty() || num.length() > 4) {
return NEITHER;
}
for (int j = 0; j < num.length(); j++) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/g0401_0500/s0488_zuma_game/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ private int dfs(String board, String hand) {
}

private int findMinStepDp(String board, String hand, Map<String, Map<String, Integer>> dp) {
if (board.length() == 0) {
if (board.isEmpty()) {
return 0;
}
if (hand.length() == 0) {
if (hand.isEmpty()) {
return -1;
}
if (dp.get(board) != null && dp.get(board).get(hand) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Solution {
public boolean detectCapitalUse(String word) {
if (word == null || word.length() == 0) {
if (word == null || word.isEmpty()) {
return false;
}
int upper = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Solution {
public int strangePrinter(String s) {
if (s.length() == 0) {
if (s.isEmpty()) {
return 0;
}
int[][] dp = new int[s.length()][s.length()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Solution {
public String makeLargestSpecial(String s) {
if (s == null || s.length() == 0 || s.length() == 2) {
if (s == null || s.isEmpty() || s.length() == 2) {
return s;
}
PriorityQueue<String> pq = new PriorityQueue<>((a, b) -> b.compareTo(a));
Expand All @@ -32,7 +32,7 @@ public String makeLargestSpecial(String s) {
while (!pq.isEmpty()) {
ans.append(pq.poll());
}
if (ans.length() == 0) {
if (ans.isEmpty()) {
ans.append('1');
ans.append(makeLargestSpecial(s.substring(1, s.length() - 1)));
ans.append('0');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<String> commonChars(String[] words) {
}

private String getCommon(String s1, String s2) {
if (s1.length() == 0 || s2.length() == 0) {
if (s1.isEmpty() || s2.isEmpty()) {
return "";
}
int[] c1c = countChars(s1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Solution {
public String alphabetBoardPath(String target) {
if (target.length() == 0) {
if (target.isEmpty()) {
return "";
}
int sourceRow = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Solution {
public boolean halvesAreAlike(String s) {
if (s.length() < 1) {
if (s.isEmpty()) {
return false;
}
return countVowel(0, s.length() / 2, s) == countVowel(s.length() / 2, s.length(), s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class Solution {
public int maximumRemovals(String s, String p, int[] removable) {
if (s == null || s.length() == 0) {
if (s == null || s.isEmpty()) {
return 0;
}
// binary search for the k which need to be removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ private void calculateHash() {
folder.calculateHash();
builder.append('#');
builder.append(foldername);
if (folder.folderHash.length() > 0) {
if (!folder.folderHash.isEmpty()) {
builder.append('(');
builder.append(folder.folderHash);
builder.append(')');
}
}
folderHash = builder.toString();
if (folderHash.length() > 0) {
if (!folderHash.isEmpty()) {
ArrayList<Folder> duplicateFolders =
duplicates.computeIfAbsent(folderHash, k -> new ArrayList<>());
duplicateFolders.add(this);
Expand Down
Loading