+ 2

Deja Vu [Challenge Question](Hard)

Will you please check the efficiency? Is their any method to reduce this piece of code? https://code.sololearn.com/cGb08YHAqR99/?ref=app

20th Mar 2022, 10:50 AM
Md Saif Ali
Md Saif Ali - avatar
1 Respuesta
+ 2
/*Don't much look into efficiency, for simple small programs... There is not much difference. . Instead , look for simple and readable.. Hope it helps.. */ import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s = sc.nextLine(); int i,l=s.length(); boolean check=true; for(i=0;i<l;i++) { char c=s.charAt(i); for(int j=i+1; j<l; j++) { if(c == s.charAt(j)) { check=false; i=l; // to don't repeat outer loop.. break; } } } if(check) System.out.print ("Unique"); else System.out.print ("Deja Vu"); } }
20th Mar 2022, 11:48 AM
Jayakrishna 🇮🇳