You are viewing a single comment's thread. Return to all comments →
This is a beginner way of coding, think more about defining your own Algorithms than using predefined methods...
public static String getSmallestAndLargest(String s, int k) {
String sequence = s.substring(0, k); String smallest = sequence; String largest = sequence; // Complete the function for(int i = 1; i <= (s.length() - k); i++){ sequence = s.substring(i, (i + k)); if(sequence.compareTo(smallest) < 0){ smallest = sequence; } if(sequence.compareTo(largest) > 0){ largest = sequence; } } 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 →
This is a beginner way of coding, think more about defining your own Algorithms than using predefined methods...
public static String getSmallestAndLargest(String s, int k) {