Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++

class Solution {
public:
    int minimumSum(int num) {
        string s = to_string(num);
	    sort(s.begin(), s.end());
	    string new1, new2;
	    for (int i = 0; i < s.length(); i++)
	     {
		     if (i % 2 == 0)
			     new1 += s[i];
		     else
			     new2 += s[i];
	     }
	     return stoi(new1) + stoi(new2);
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Minimum #Sum #Four #Digit #Number #After #Splitting #Digits #leetcode #solution
ADD COMMENT
Topic
Name
9+5 =