You are viewing a single comment's thread. Return to all comments →
instead of a lot of comparisons, just take first number and build it and then check
public static void separateNumbers(String s) { if (s.charAt(0) == '0') { System.out.println("NO"); return; } else { for (int i = 1; i < (s.length() / 2)+1; i++) { Long num = Long.valueOf(s.substring(0, i)); StringBuilder b = new StringBuilder(s.substring(0,i)); Long l = Long.valueOf(num); while (b.length() < s.length()) { b.append(l + 1); l = l + 1; } if (b.toString().equals(s)) { System.out.println("YES " + num); return; } } System.out.println("NO"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →
instead of a lot of comparisons, just take first number and build it and then check