We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Stringsmallest=s.substring(0,k);Stringlargest=s.substring(2,5);// Complete the function// 'smallest' must be the lexicographically smallest substring of length 'k'// 'largest' must be the lexicographically largest substring of length 'k'for(inti=0;i<s.length()-k+1;i++){if(s.substring(i,i+k).compareTo(smallest)<0){smallest=s.substring(i,i+k);}elseif(s.substring(i,i+k).compareTo(largest)>0){largest=s.substring(i,i+k);}}
Java Substring Comparisons
You are viewing a single comment's thread. Return to all comments →
Here is my way, hope it could help someone