mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 04:20:16 +08:00
Add automatic linter (#4214)
This commit is contained in:
@ -19,14 +19,10 @@ public class Anagrams {
|
||||
String second = "lead";
|
||||
// All the below methods takes input but doesn't return any output to the main method.
|
||||
Anagrams nm = new Anagrams();
|
||||
System.out.println(
|
||||
nm.approach2(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(
|
||||
nm.approach1(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(
|
||||
nm.approach3(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(
|
||||
nm.approach4(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(nm.approach2(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(nm.approach1(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(nm.approach3(first, second)); /* To activate methods for different approaches*/
|
||||
System.out.println(nm.approach4(first, second)); /* To activate methods for different approaches*/
|
||||
/**
|
||||
* OUTPUT :
|
||||
* first string ="deal" second string ="lead"
|
||||
|
@ -11,8 +11,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class CheckVowels {
|
||||
|
||||
private static final Set<Character> VOWELS
|
||||
= new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
|
||||
private static final Set<Character> VOWELS = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
|
||||
|
||||
/**
|
||||
* Check if a string is has vowels or not
|
||||
|
@ -100,8 +100,7 @@ public class HorspoolSearch {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int textIndex = pattern.length()
|
||||
- 1; // align pattern with text start and get index of the last character
|
||||
int textIndex = pattern.length() - 1; // align pattern with text start and get index of the last character
|
||||
|
||||
// while pattern is not out of text bounds
|
||||
while (textIndex < text.length()) {
|
||||
@ -111,8 +110,7 @@ public class HorspoolSearch {
|
||||
comparisons++;
|
||||
char patternChar = pattern.charAt(i);
|
||||
char textChar = text.charAt((textIndex + i) - (pattern.length() - 1));
|
||||
if (!charEquals(
|
||||
patternChar, textChar, caseSensitive)) { // bad character, shift pattern
|
||||
if (!charEquals(patternChar, textChar, caseSensitive)) { // bad character, shift pattern
|
||||
textIndex += getShiftValue(text.charAt(textIndex));
|
||||
break;
|
||||
}
|
||||
@ -159,8 +157,7 @@ public class HorspoolSearch {
|
||||
patternLength = pattern.length();
|
||||
HashMap<Character, Integer> table = new HashMap<>();
|
||||
|
||||
for (int i = pattern.length() - 2; i >= 0;
|
||||
i--) { // length - 2 is the index of the second to last character
|
||||
for (int i = pattern.length() - 2; i >= 0; i--) { // length - 2 is the index of the second to last character
|
||||
char c = pattern.charAt(i);
|
||||
int finalI = i;
|
||||
table.computeIfAbsent(c, k -> pattern.length() - 1 - finalI);
|
||||
|
@ -13,8 +13,7 @@ class Palindrome {
|
||||
* {@code false}
|
||||
*/
|
||||
public static boolean isPalindrome(String s) {
|
||||
return (
|
||||
(s == null || s.length() <= 1) || s.equals(new StringBuilder(s).reverse().toString()));
|
||||
return ((s == null || s.length() <= 1) || s.equals(new StringBuilder(s).reverse().toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,8 +33,7 @@ public class StringCompression {
|
||||
break;
|
||||
} else if (input.charAt(i) != input.charAt(i + 1)) {
|
||||
if ((i + 1) == input.length() - 1) {
|
||||
compressedString = appendCount(compressedString, count, input.charAt(i))
|
||||
+ input.charAt(i + 1);
|
||||
compressedString = appendCount(compressedString, count, input.charAt(i)) + input.charAt(i + 1);
|
||||
break;
|
||||
} else {
|
||||
compressedString = appendCount(compressedString, count, input.charAt(i));
|
||||
|
@ -7,8 +7,7 @@ class zigZagPattern {
|
||||
int start = 0, index = 0, height = 1, depth = numRows;
|
||||
char[] zigZagedArray = new char[s.length()];
|
||||
while (depth != 0) {
|
||||
int pointer = start, height_space = 2 + ((height - 2) * 2),
|
||||
depth_space = 2 + ((depth - 2) * 2);
|
||||
int pointer = start, height_space = 2 + ((height - 2) * 2), depth_space = 2 + ((depth - 2) * 2);
|
||||
boolean bool = true;
|
||||
while (pointer < s.length()) {
|
||||
zigZagedArray[index++] = s.charAt(pointer);
|
||||
|
Reference in New Issue
Block a user