Description
Submission
class Solution {
string arbitrate(string& a, string& b) {
// a.length() >= b.length()
int len = a.length() + b.length();
string ret;
for(int i = 0; i < len; ++i) {
if(i % 2 == 0) ret.push_back(a[i>>1]);
else ret.push_back(b[i>>1]);
}
return ret;
}
public:
string reformat(string s) {
string nums, chars;
for(char ch: s) {
if(ch >= 'a' && ch <= 'z') chars.push_back(ch);
else nums.push_back(ch);
}
if(nums.length() > chars.length() + 1 || chars.length() > nums.length() + 1) return "";
if(nums.length() > chars.length()) return arbitrate(nums, chars);
return arbitrate(chars, nums);
}
};