File tree 6 files changed +108
-4
lines changed
1300-1399/1342.Number of Steps to Reduce a Number to Zero
1600-1699/1678.Goal Parser Interpretation
6 files changed +108
-4
lines changed Original file line number Diff line number Diff line change 68
68
<!-- 这里可写当前语言的特殊实现逻辑 -->
69
69
70
70
``` java
71
-
71
+ class Solution {
72
+ public int numberOfSteps (int num ) {
73
+ int cnt = 0 ;
74
+ while (num != 0 ) {
75
+ if (num % 2 == 1 )
76
+ num-- ;
77
+ else
78
+ num /= 2 ;
79
+ cnt++ ;
80
+ }
81
+ return cnt;
82
+ }
83
+ }
72
84
```
73
85
74
86
### ** ...**
Original file line number Diff line number Diff line change @@ -61,7 +61,19 @@ Step 4) 1 is odd; subtract 1 and obtain 0.
61
61
### ** Java**
62
62
63
63
``` java
64
-
64
+ class Solution {
65
+ public int numberOfSteps (int num ) {
66
+ int cnt = 0 ;
67
+ while (num != 0 ) {
68
+ if (num % 2 == 1 )
69
+ num-- ;
70
+ else
71
+ num /= 2 ;
72
+ cnt++ ;
73
+ }
74
+ return cnt;
75
+ }
76
+ }
65
77
```
66
78
67
79
### ** ...**
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int numberOfSteps (int num ) {
3
+ int cnt = 0 ;
4
+ while (num != 0 ) {
5
+ if (num % 2 == 1 )
6
+ num --;
7
+ else
8
+ num /= 2 ;
9
+ cnt ++;
10
+ }
11
+ return cnt ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change @@ -64,7 +64,29 @@ G -> G
64
64
<!-- 这里可写当前语言的特殊实现逻辑 -->
65
65
66
66
``` java
67
-
67
+ class Solution {
68
+ public String interpret (String command ) {
69
+ StringBuilder sb = new StringBuilder ();
70
+ int p = 0 , q = 1 ;
71
+ for (; p < command. length(); p++ , q++ ) {
72
+ char c = command. charAt(p);
73
+ if (c == ' G' )
74
+ sb. append(' G' );
75
+ if (c == ' (' ) {
76
+ if (command. charAt(q) == ' )' ) {
77
+ sb. append(" o" );
78
+ p++ ;
79
+ q++ ;
80
+ } else {
81
+ sb. append(" al" );
82
+ p += 2 ;
83
+ q += 2 ;
84
+ }
85
+ }
86
+ }
87
+ return sb. toString();
88
+ }
89
+ }
68
90
```
69
91
70
92
### ** ...**
Original file line number Diff line number Diff line change @@ -57,7 +57,29 @@ The final concatenated result is "Goal".
57
57
### ** Java**
58
58
59
59
``` java
60
-
60
+ class Solution {
61
+ public String interpret (String command ) {
62
+ StringBuilder sb = new StringBuilder ();
63
+ int p = 0 , q = 1 ;
64
+ for (; p < command. length(); p++ , q++ ) {
65
+ char c = command. charAt(p);
66
+ if (c == ' G' )
67
+ sb. append(' G' );
68
+ if (c == ' (' ) {
69
+ if (command. charAt(q) == ' )' ) {
70
+ sb. append(" o" );
71
+ p++ ;
72
+ q++ ;
73
+ } else {
74
+ sb. append(" al" );
75
+ p += 2 ;
76
+ q += 2 ;
77
+ }
78
+ }
79
+ }
80
+ return sb. toString();
81
+ }
82
+ }
61
83
```
62
84
63
85
### ** ...**
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public String interpret (String command ) {
3
+ StringBuilder sb = new StringBuilder ();
4
+ int p = 0 , q = 1 ;
5
+ for (; p < command .length (); p ++, q ++) {
6
+ char c = command .charAt (p );
7
+ if (c == 'G' )
8
+ sb .append ('G' );
9
+ if (c == '(' ) {
10
+ if (command .charAt (q ) == ')' ) {
11
+ sb .append ("o" );
12
+ p ++;
13
+ q ++;
14
+ } else {
15
+ sb .append ("al" );
16
+ p += 2 ;
17
+ q += 2 ;
18
+ }
19
+ }
20
+ }
21
+ return sb .toString ();
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments