Skip to content

Commit ab19976

Browse files
ajustes
1 parent 660ad59 commit ab19976

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/main/java/com/hackerrank/SeparateNumbers.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ class SeparateNumbersResult {
2727
*/
2828

2929
public static void separateNumbers(String s) {
30+
int count=0;
3031
int pivot=0;
3132
int len=1;
3233
List<String> beautifull = new ArrayList<>();
3334
int next = pivot+len;
3435
int end = next+len;
3536
String first;
3637
String second;
37-
System.out.println(s);
38+
//System.out.println(s);
3839
if(s.length()<2){
3940
System.out.println("NO");
4041
} else if (s.length()==2){
@@ -46,30 +47,27 @@ public static void separateNumbers(String s) {
4647
first = s.substring(pivot, next);
4748
second = s.substring(next, end);
4849

49-
System.out.printf("First: %s -> Second: %s%n", first, second);
50+
// System.out.printf("First: %s -> Second: %s%n", first, second);
5051

51-
52-
if(first.charAt(first.length()-1) == '9'){
53-
end++;
54-
System.out.println("Aumenta o end -> "+end);
52+
if(second.charAt(0) == '0' | second.length()>first.length()){
53+
++len;
54+
//System.out.println("Aumenta o len -> "+len);
55+
} else if(first.charAt(first.length()-1) == '9' || first.length()>second.length()){
56+
++end;
57+
//System.out.println("Aumenta o end -> "+end);
5558
}
5659

5760
if(Integer.parseInt(second) == Integer.parseInt(first)+1){
5861
beautifull.add(first);
59-
++pivot;
60-
System.out.println("Aumenta o pivot -> "+pivot);
61-
//next=pivot+len;
62-
end = next+len;
62+
pivot=next;
63+
//System.out.println("Aumenta o pivot -> "+pivot);
64+
end = end+len;
6365
}
6466

65-
if(second.charAt(0) == '0' | second.length()>first.length()){
66-
++len;
67-
System.out.println("Aumenta o len -> "+len);
68-
}
6967
next = pivot+len;
70-
//end = next+len;
71-
72-
} while (end<=s.length());
68+
count++;
69+
70+
} while (end<s.length() || next<s.length() || count>200);
7371

7472
if(Integer.parseInt(second) == Integer.parseInt(first)+1)
7573
beautifull.add(second);

0 commit comments

Comments
 (0)