Calculate Digit Sum of a String Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n*m)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution {\npublic:\n    string digitSum(string s, int k) {\n        int i, j=0, l, n;\n        string temp="";\n        while(s.length()>k)\n        {\n            j=0;\n            l = s.length()/k;\n            while(l--)\n            {\n                for(i=j ; i<j+k ; i++)\n                {\n                    n += s[i]-48;\n                }\n                j = j+k;\n                temp += to_string(n);\n                n=0;\n            }\n            if(s.length()%k!=0)\n            {\n                for(i=j ; i<s.length() ; i++)\n                {\n                    n += s[i]-48;\n                }\n                temp += to_string(n);\n                n=0;\n            }\n            s.clear();\n            s = temp;\n            temp.clear();\n        }\n        return s;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/af207ac5-cef2-406d-b647-0f6e145ac565_1685591499.707829.jpeg)\n
['C++']