forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2243.java
More file actions
21 lines (20 loc) · 660 Bytes
/
_2243.java
File metadata and controls
21 lines (20 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.fishercoder.solutions;
public class _2243 {
public static class Solution1 {
public String digitSum(String s, int k) {
StringBuilder sb = new StringBuilder();
while (s.length() > k) {
for (int i = 0; i < s.length(); i += k) {
int sum = 0;
for (int j = i; j < i + k && j < s.length(); j++) {
sum += Integer.parseInt(s.charAt(j) + "");
}
sb.append(sum);
}
s = sb.toString();
sb.setLength(0);
}
return s;
}
}
}