隔空依次取值,相加最小,原理暂不清楚,举例演示就可发现。
class Solution {
public:
int splitNum(int num) {
int num1=0,num2=0;
vector<int> a;
while(num){
a.push_back(num%10);
num/=10;
}
sort(a.begin(),a.end());
for(int i=0;i<a.size();i+=2){
num1=num1*10+a[i];
}
for(int i=1;i<a.size();i+=2){
num2=num2*10+a[i];
}
return num1+num2;
}
};
标签:10,2578,int,最小,力扣,num,依次,排序
From: https://blog.51cto.com/u_15974747/8331148