You are viewing a single comment's thread. Return to all comments →
public static String getSmallestAndLargest(String s, int k){ String smallest = ""; String largest = "";
String[] arr = new String[s.length()+1-k]; for(int i =0 ; i<s.length();i++){ if(i!=s.length()-k){ arr[i] = s.substring(i, k+i); }else{ arr[i] = s.substring(i, k+i); break; } } smallest = arr[0]; largest = arr[0]; for (int i=1;i< arr.length;i++){ if(arr[i].compareTo(largest)>0){ largest = arr[i]; } if (arr[i].compareTo(smallest)<0) { smallest= arr[i]; } } 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 →
public static String getSmallestAndLargest(String s, int k){ String smallest = ""; String largest = "";