0
How to avoid nested loop in this program
I want to make the program more efficient import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner ob =new Scanner(System.in); String s=ob.nextLine(); int c=0; for(int i=0;i<s.length()-1;i++) { for(int j=(i+1);j<s.length();j++) { if(s.charAt(i)==s.charAt(j)) { c++;break; } } } if(c>0) System.out.println("Deja Vu"); else System.out.println("Unique"); } }
1 ответ
+ 1
You can try to do this way. With boolean array. Pretty simple solution and you can avoid double for loop.
https://code.sololearn.com/c6iDFjEgbmTu/?ref=app