Below is my code for Q1 of 288th Leetcode weekly contest. When I submit my code it gives wrong answer at test case 10e9. Can anyone point out my mistake in the code?
class Solution {
public:
int largestInteger(int num) {
int n=floor(log(num)/log(10))+1;
long long int answer=0;
vector<bool> pari(n);
vector<int> odd, even;
for (int z=0; num!=0; z++, num/=10) {
if ((num%10)%2==0) {
pari[z]=false;
even.push_back(num%10);
} else {
pari[z]=true;
odd.push_back(num%10);
}
}
sort(odd.begin(), odd.end());
sort(even.begin(), even.end());
reverse(odd.begin(), odd.end());
reverse(even.begin(), even.end());
reverse(pari.begin(), pari.end());
int y=0, x=0;
for (int z=0; z<n; z++) {
if (pari[z]) {
answer=answer*10+odd[y++];
} else {
answer=answer*10+even[x++];
}
}
return answer;
}
};