Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 58cc092

Browse files
add 2243
1 parent d7d90e6 commit 58cc092

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
11+
| 2243 |[Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2243.java) || Easy ||
1112
| 2220 |[Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2220.java) || Easy ||
1213
| 2215 |[Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2215.java) || Easy ||
1314
| 2210 |[Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2210.java) || Easy ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2243 {
4+
public static class Solution1 {
5+
public String digitSum(String s, int k) {
6+
StringBuilder sb = new StringBuilder();
7+
while (s.length() > k) {
8+
for (int i = 0; i < s.length(); i += k) {
9+
int sum = 0;
10+
for (int j = i; j < i + k && j < s.length(); j++) {
11+
sum += Integer.parseInt(s.charAt(j) + "");
12+
}
13+
sb.append(sum);
14+
}
15+
s = sb.toString();
16+
sb.setLength(0);
17+
}
18+
return s;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)