-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path379.h
More file actions
33 lines (29 loc) · 809 Bytes
/
379.h
File metadata and controls
33 lines (29 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
/*
* @param nums: n non-negative integer array
* @return: A string
*/
string minNumber(vector<int> nums) {
// write your code here
sort(nums.begin(), nums.end(), less);
string res = "";
if(nums.size()==0) return res;
int i = 0;
for(; i < nums.size(); i++){
if(nums[i] != 0 ) break;
}
for(; i < nums.size(); i++){
res += to_string(nums[i]);
}
if(res == "") return "0";
else return res;
}
static bool less(int num1, int num2){
string str1 = to_string(num1);
string str2 = to_string(num2);
string res1 = str1 + str2;
string res2 = str2 + str1;
return res1 < res2;
}
};