Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string strWithout3a3b(int A, int B) {
- pair<int,int> cnt = {max(A, B), min(A,B)};
- pair<char,char> alph = {(A > B) ? 'a' : 'b', (A > B) ? 'b' : 'a'};
- string ans = "";
- while(cnt.first > 0 && cnt.second > 0 && cnt.first > cnt.second){
- ans.push_back(alph.first);
- ans.push_back(alph.first);
- cnt.first-=2;
- ans.push_back(alph.second);
- cnt.second--;
- }
- while(cnt.first > 0 || cnt.second > 0){
- if(cnt.first > 0) {
- ans.push_back(alph.first);
- cnt.first--;
- }
- if(cnt.second > 0) {
- ans.push_back(alph.second);
- cnt.second--;
- }
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment