Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int compress(vector<char>& chars) {
- int i=0,j=0;
- while(i<chars.size())
- {
- int count=1;
- while(i+count<chars.size() && chars[i+count]==chars[i])
- {
- count++;
- }
- chars[j++]=chars[i];
- if(count>1)
- {
- for(char c:to_string(count))
- {
- chars[j++]=c;
- }
- }
- i+=count;
- }
- return j;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement