Skip to content

feat: add java solution to lc problem: No.1342 and No.1678 #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@
<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

class Solution {
public int numberOfSteps(int num) {
int cnt = 0;
while (num != 0) {
if (num % 2 == 1)
num--;
else
num /= 2;
cnt++;
}
return cnt;
}
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@ Step 4) 1 is odd; subtract 1 and obtain 0.
### **Java**

```java

class Solution {
public int numberOfSteps(int num) {
int cnt = 0;
while (num != 0) {
if (num % 2 == 1)
num--;
else
num /= 2;
cnt++;
}
return cnt;
}
}
```

### **...**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public int numberOfSteps(int num) {
int cnt = 0;
while (num != 0) {
if (num % 2 == 1)
num--;
else
num /= 2;
cnt++;
}
return cnt;
}
}
24 changes: 23 additions & 1 deletion solution/1600-1699/1678.Goal Parser Interpretation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,29 @@ G -&gt; G
<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

class Solution {
public String interpret(String command) {
StringBuilder sb = new StringBuilder();
int p = 0, q = 1;
for (; p < command.length(); p++, q++) {
char c = command.charAt(p);
if (c == 'G')
sb.append('G');
if (c == '(') {
if (command.charAt(q) == ')') {
sb.append("o");
p++;
q++;
} else {
sb.append("al");
p += 2;
q += 2;
}
}
}
return sb.toString();
}
}
```

### **...**
Expand Down
24 changes: 23 additions & 1 deletion solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,29 @@ The final concatenated result is &quot;Goal&quot;.
### **Java**

```java

class Solution {
public String interpret(String command) {
StringBuilder sb = new StringBuilder();
int p = 0, q = 1;
for (; p < command.length(); p++, q++) {
char c = command.charAt(p);
if (c == 'G')
sb.append('G');
if (c == '(') {
if (command.charAt(q) == ')') {
sb.append("o");
p++;
q++;
} else {
sb.append("al");
p += 2;
q += 2;
}
}
}
return sb.toString();
}
}
```

### **...**
Expand Down
23 changes: 23 additions & 0 deletions solution/1600-1699/1678.Goal Parser Interpretation/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public String interpret(String command) {
StringBuilder sb = new StringBuilder();
int p = 0, q = 1;
for (; p < command.length(); p++, q++) {
char c = command.charAt(p);
if (c == 'G')
sb.append('G');
if (c == '(') {
if (command.charAt(q) == ')') {
sb.append("o");
p++;
q++;
} else {
sb.append("al");
p += 2;
q += 2;
}
}
}
return sb.toString();
}
}