You are viewing a single comment's thread. Return to all comments →
ArrayList<String> substrings = new ArrayList<>(); for(int i=0;i<=s.length()-k;i++){ String sub = s.substring(i,i+k); substrings.add(sub); } smallest = substrings.get(0); largest = substrings.get(0); for(int j=1;j<substrings.size();j++){ String currentword = substrings.get(j); if(currentword.compareTo(smallest)<0){ smallest=currentword; } if(currentword.compareTo(largest)>0){ largest=currentword; } } return smallest + "\n" + largest; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Substring Comparisons
You are viewing a single comment's thread. Return to all comments →