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.
- Prepare
- Java
- Strings
- Java Substring Comparisons
- Discussions
Java Substring Comparisons
Java Substring Comparisons
Sort by
recency
|
1740 Discussions
|
Please Login in order to post a comment
Scanner scan = new Scanner(System.in); String s = scan.nextLine(); int k = Integer.parseInt(scan.nextLine()); int N = s.length()-(k-1); String[] arr = new String[N]; for(int i=0;i
import java.util.Scanner;
public class Solution { static String getSmallestAndLargest(String s, int k) { String smallest = s.substring(0,k); String largest = s.substring(0,k); for(int i=1;i<=s.length()-k;i++){ String sub = s.substring(i,i+k); int d = smallest.compareTo(sub); if(d>0) smallest = sub; String new_sub = s.substring(i,i+k); int p = largest.compareTo(new_sub); if(p<0) largest = new_sub;
}
public static String getSmallestAndLargest(String s, int k) {
how to think like you efficiently, i tried with twice as many lines and still got largest wrong and smallest right
Don't laugh, I'm just a beginner too)))). Just keep doing and analyzing other people's good cod. Everything will be great.
Well i think u will pass time complexity cases very easily, thanks for suggestion
import java.io.; import java.util.; import java.util.stream.*;
public class Solution {
}
Why are you making it so complex when it can be done so simply and cleanly.