From dd947ede8590a206631324228e627de7003873e0 Mon Sep 17 00:00:00 2001 From: My <34188127+0xcaffebabe@users.noreply.github.com> Date: Thu, 29 Jul 2021 10:52:41 +0800 Subject: [PATCH 1/5] feat: add java solution to lc problem: No.1342.Number of Steps to Reduce a Number to Zero --- .../README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md index 7a62b4fcf7c8c..f6d2a9ecf092e 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md @@ -68,7 +68,17 @@ ```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; + } +} ``` ### **...** From 942cc4cf1c9c5cd06278954f9c172779b3dfe7b9 Mon Sep 17 00:00:00 2001 From: My <34188127+0xcaffebabe@users.noreply.github.com> Date: Thu, 29 Jul 2021 11:00:52 +0800 Subject: [PATCH 2/5] feat: add java solution to lc problem: No. 1678.Goal Parser Interpretation --- .../1678.Goal Parser Interpretation/README.md | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/solution/1600-1699/1678.Goal Parser Interpretation/README.md b/solution/1600-1699/1678.Goal Parser Interpretation/README.md index f297c7e47fec3..750e62adb7332 100644 --- a/solution/1600-1699/1678.Goal Parser Interpretation/README.md +++ b/solution/1600-1699/1678.Goal Parser Interpretation/README.md @@ -64,7 +64,29 @@ G -> G ```java - +class Solution { + public String interpret(String command) { + StringBuilder sb = new StringBuilder(); + int p = 0,q = 1; + for(;p Date: Thu, 29 Jul 2021 11:14:37 +0800 Subject: [PATCH 3/5] feat: add java solution to lc problem: No.1342.Number of Steps to Reduce a Number to Zero --- .../README_EN.md | 12 +++++++++++- .../Solution.java | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md index af2a514685466..82cf464eb4d53 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md @@ -61,7 +61,17 @@ 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; + } +} ``` ### **...** diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java new file mode 100644 index 0000000000000..06298a9fcaea1 --- /dev/null +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java @@ -0,0 +1,11 @@ +class Solution { + public int numberOfSteps(int num) { + int cnt = 0; + while(num != 0) { + if (num % 2 == 1) num--; + else num /= 2; + cnt++; + } + return cnt; + } +} \ No newline at end of file From d4572356dcc278c0b2266289c3e682a3607a246e Mon Sep 17 00:00:00 2001 From: cjiping Date: Thu, 29 Jul 2021 11:15:28 +0800 Subject: [PATCH 4/5] add java solution to lc problem: No.1678.Goal Parser Interpretation --- .../README_EN.md | 24 ++++++++++++++++++- .../Solution.java | 23 ++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 solution/1600-1699/1678.Goal Parser Interpretation/Solution.java diff --git a/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md b/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md index 851e3617808e8..3e64bc9e55f12 100644 --- a/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md +++ b/solution/1600-1699/1678.Goal Parser Interpretation/README_EN.md @@ -57,7 +57,29 @@ The final concatenated result is "Goal". ### **Java** ```java - +class Solution { + public String interpret(String command) { + StringBuilder sb = new StringBuilder(); + int p = 0,q = 1; + for(;p Date: Thu, 29 Jul 2021 11:30:51 +0800 Subject: [PATCH 5/5] feat: code format --- .../README.md | 8 +++++--- .../README_EN.md | 8 +++++--- .../Solution.java | 8 +++++--- .../1678.Goal Parser Interpretation/README.md | 10 +++++----- .../1678.Goal Parser Interpretation/README_EN.md | 10 +++++----- .../1678.Goal Parser Interpretation/Solution.java | 10 +++++----- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md index f6d2a9ecf092e..59b8e45e1dd8c 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README.md @@ -71,9 +71,11 @@ class Solution { public int numberOfSteps(int num) { int cnt = 0; - while(num != 0) { - if (num % 2 == 1) num--; - else num /= 2; + while (num != 0) { + if (num % 2 == 1) + num--; + else + num /= 2; cnt++; } return cnt; diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md index 82cf464eb4d53..e828822776c9b 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/README_EN.md @@ -64,9 +64,11 @@ Step 4) 1 is odd; subtract 1 and obtain 0. class Solution { public int numberOfSteps(int num) { int cnt = 0; - while(num != 0) { - if (num % 2 == 1) num--; - else num /= 2; + while (num != 0) { + if (num % 2 == 1) + num--; + else + num /= 2; cnt++; } return cnt; diff --git a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java index 06298a9fcaea1..fd6ac2dfc9993 100644 --- a/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java +++ b/solution/1300-1399/1342.Number of Steps to Reduce a Number to Zero/Solution.java @@ -1,9 +1,11 @@ class Solution { public int numberOfSteps(int num) { int cnt = 0; - while(num != 0) { - if (num % 2 == 1) num--; - else num /= 2; + while (num != 0) { + if (num % 2 == 1) + num--; + else + num /= 2; cnt++; } return cnt; diff --git a/solution/1600-1699/1678.Goal Parser Interpretation/README.md b/solution/1600-1699/1678.Goal Parser Interpretation/README.md index 750e62adb7332..9e1be1167bd55 100644 --- a/solution/1600-1699/1678.Goal Parser Interpretation/README.md +++ b/solution/1600-1699/1678.Goal Parser Interpretation/README.md @@ -67,17 +67,17 @@ G -> G class Solution { public String interpret(String command) { StringBuilder sb = new StringBuilder(); - int p = 0,q = 1; - for(;p