You are viewing a single comment's thread. Return to all comments →
I just "improved" (it doesnt use magic number, and I check if its empty the string one time, but I use more memory) another solution I found on this discussion section. the og solution: https://programmingoneonone.com/hackerrank-java-string-tokens-problem-solution.html
import java.util.*; public class Solution { public static void main(String[] args) { final String splitRegEx = "[^a-zA-Z]"; List<String> listStrSplited = new LinkedList<>(); Scanner scan = new Scanner(System.in); String s = scan.nextLine(); scan.close(); String [] draftlistStrSplited = s.split(splitRegEx); for(String splittedStr : draftlistStrSplited){ if(!splittedStr.isEmpty()){ listStrSplited.add(splittedStr); } } System.out.println(listStrSplited.size()); for(String splittedStr : listStrSplited){ System.out.println(splittedStr); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java String Tokens
You are viewing a single comment's thread. Return to all comments →
I just "improved" (it doesnt use magic number, and I check if its empty the string one time, but I use more memory) another solution I found on this discussion section. the og solution: https://programmingoneonone.com/hackerrank-java-string-tokens-problem-solution.html