The only way to keep your game at a very high level is being challenged every day. Nice source of coding challenges at https://leetcode.com Let's dive into it!
- Java 21
- IntelliJ Community Edition
- Gradle
- LeetCode Challenge75 - @Ricardo Ferreira
- Tools
- Table of contents
- Screenshot
- Links
- Built with
- What I practiced
- Continued development
- Author
- Acknowledgments
- Live Site URL: [https://leetcode.com/u/rferreira_757/]
public static boolean validAnagram(String s1, String s2) throws InterruptedException {
logger.info("Starting Anagram.... - V2");
startTimer();
String regex = "\\s+";
s1 = s1.replaceAll(regex, "").toLowerCase();
s2 = s2.replaceAll(regex, "").toLowerCase();
int lenStringOne = s1.length(), lenStringTwo = s2.length();
logger.info(String.format("Length of each string provided as is: %d, %d", lenStringOne, lenStringTwo));
if (lenStringOne != lenStringTwo) {
logger.info("Its not feasible to have an anagram with the strings provided. Try again!");
timeTaken();
return false;
}
logger.info("Both strings are normalized..." + s1);
char[] stringOne = s1.toCharArray(),stringTwo = s2.toCharArray();
StringBuilder sbOne = new StringBuilder(), sbTwo = new StringBuilder();
Thread thread = new Thread( () -> {
Arrays.sort(stringOne);
Arrays.sort(stringTwo);
logger.info("Both strings are sorted...");
for (char c : stringOne) {
sbOne.append(c);
}
for (char c : stringTwo) {
sbTwo.append(c);
}
});
thread.start();
thread.join();
logger.info("Stopping watch...");
timeTaken();
stopWatchReset();
return sbOne.toString().contentEquals(sbTwo.toString());
}
- Next step: Threads, Concurrency, Parallelism. ExecutorService and CompletableFuture
- [https://docs.oracle.com/en/java/] Always trust and read the official documentation!
- [https://cp-algorithms.com/] A must stop by to tackle DSA...
- Website - [https://www.ferreiras.dev.br]