MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / getLucky

Method getLucky

sumOfDigitsOfStringAfterConvert.java:3–17  ·  view source on GitHub ↗
(String s, int k)

Source from the content-addressed store, hash-verified

1// 1st approach
2class Solution {
3 public int getLucky(String s, int k) {
4 StringBuilder sb = new StringBuilder();
5 for(char ch : s.toCharArray()){
6 sb.append(ch-96);
7 }
8 while(k>0){
9 int sum=0;
10 for(int i=0;i<sb.length();i++){
11 sum += (sb.charAt(i) - '0');
12 }
13 k--;
14 sb = new StringBuilder(String.valueOf(sum));
15 }
16 return Integer.parseInt(sb.toString());
17 }
18}
19
20

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected