From b416d1f161f3917936669a986ce5be2459dd8ddf Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:34:53 +0530 Subject: [PATCH] Create 1945. Sum of Digits of String After Convert --- 1945. Sum of Digits of String After Convert | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 1945. Sum of Digits of String After Convert diff --git a/1945. Sum of Digits of String After Convert b/1945. Sum of Digits of String After Convert new file mode 100644 index 0000000..fc04911 --- /dev/null +++ b/1945. Sum of Digits of String After Convert @@ -0,0 +1,37 @@ +class Solution { +public: + int transform(int num){ + + int sum = 0; + + while(num>0){ + + int digit = num % 10; + sum += digit; + num /= 10; + + } + + return sum; + + } + int getLucky(string s, int k) { + + string str; + + for (auto& c : s) { + str += to_string((c - 'a') + 1); + } + + int sum = 0; + for (auto& digits : str) { + sum += digits - '0'; + } + + for(int i=1;i