We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 97e1fbb commit 96ccf6eCopy full SHA for 96ccf6e
scripts/algorithms/C/Calculate Digit Sum of a String/Calculate Digit Sum of a String.java
@@ -0,0 +1,16 @@
1
+// Runtime: 6 ms (Top 32.40%) | Memory: 40.8 MB (Top 89.31%)
2
+class Solution {
3
+ public String digitSum(String s, int k) {
4
+ while(s.length() > k) s = gen(s,k);
5
+ return s;
6
+ }
7
+ public String gen(String s,int k){
8
+ String res = "";
9
+ for(int i=0;i < s.length();){
10
+ int count = 0,num=0;
11
+ while(i < s.length() && count++ < k) num += Character.getNumericValue(s.charAt(i++));
12
+ res+=num;
13
14
+ return res;
15
16
+}
0 commit comments