File tree Expand file tree Collapse file tree 1 file changed +3
-16
lines changed
src/main/java/by/andd3dfx/numeric Expand file tree Collapse file tree 1 file changed +3
-16
lines changed Original file line number Diff line number Diff line change @@ -35,28 +35,15 @@ public static String addStrings(String num1, String num2) {
3535
3636 var sb = new StringBuilder ();
3737 var accumulator = 0 ;
38- while (i >= 0 && j >= 0 ) {
39- int n1 = chars1 [i ] - '0' ;
40- int n2 = chars2 [j ] - '0' ;
38+ while (i >= 0 || j >= 0 || accumulator > 0 ) {
39+ int n1 = ( i >= 0 ) ? ( chars1 [i ] - '0' ) : 0 ;
40+ int n2 = ( j >= 0 ) ? ( chars2 [j ] - '0' ) : 0 ;
4141
4242 accumulator = calcAccumulator (n1 + n2 + accumulator , sb );
4343
4444 i --;
4545 j --;
4646 }
47- while (i >= 0 ) {
48- int n1 = chars1 [i ] - '0' ;
49- accumulator = calcAccumulator (n1 + accumulator , sb );
50- i --;
51- }
52- while (j >= 0 ) {
53- int n2 = chars2 [j ] - '0' ;
54- accumulator = calcAccumulator (n2 + accumulator , sb );
55- j --;
56- }
57- if (accumulator > 0 ) {
58- sb .append (accumulator );
59- }
6047
6148 return sb .reverse ().toString ();
6249 }
You can’t perform that action at this time.
0 commit comments