You are viewing a single comment's thread. Return to all comments →
Hello, can someone knowledgable help me understand why this code does not work? It seems replaceFirst(regex, replacement) doesn't work the way I expect it to from https://www.w3schools.com/java/ref_string_replacefirst.asp.
a = a.toLowerCase(); b = b.toLowerCase(); if(a.length() != b.length()) { return false; } for(int i = 0; i < b.length(); i++) { a.replaceFirst(String.valueOf(b.charAt(i)), ""); // a.replaceFirst(b.substring(i, i+1), ""); } return a.isEmpty();
(I wanted to try to not use Arrays and Hashmaps)
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Anagrams
You are viewing a single comment's thread. Return to all comments →
Hello, can someone knowledgable help me understand why this code does not work? It seems replaceFirst(regex, replacement) doesn't work the way I expect it to from https://www.w3schools.com/java/ref_string_replacefirst.asp.
(I wanted to try to not use Arrays and Hashmaps)