You are viewing a single comment's thread. Return to all comments →
can someone let me know how to optimize this code below ?
public static void main(String[] args) { int i=0; Scanner in = new Scanner(System.in); String s = in.next(); int n = in.nextInt(); int sum=0; int num[]=new int[n]; for(int a0 = 0; a0 < n; a0++) num[a0]=in.nextInt(); for(int k=0;k<n;k++) { sum=s.charAt(0)-'a'+1; if(sum==num[k]) { System.out.println("Yes"); continue; } for(i=0;(i+1)<s.length();i++) { if(s.charAt(i)==s.charAt(i+1)) { sum+=s.charAt(i)-'a'+1; } else sum=s.charAt(i+1)-'a'+1; if(sum==num[k]) { System.out.println("Yes"); break; } } if((i+1)==s.length()) System.out.println("No"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
can someone let me know how to optimize this code below ?