일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- cpp
- 조지아텍
- 개발자
- LV1
- zeros
- EOI
- 선형대수
- 딥러닝
- 캐나다 영주권
- 위니펙
- Plotting
- 기본
- Deep learning
- 주정부이민
- leetcode
- 머신러닝
- 온라인석사
- omscs
- C++
- 방통대
- 프로그래머스
- machine learning
- 알고리즘
- 매트랩
- mpnp
- 코딩테스트
- MATLAB
- LAA
- 컴퓨터과학과
- 방송통신대학교
Archives
- Today
- Total
Byte by Byte
1370. Increasing Decreasing String.cpp 본문
class Solution {
public:
string sortString(string s) {
string res="";
sort(s.begin(),s.end());
int savechar[26] ={0,};
for(int i =0; i<s.size(); i++){
savechar[s[i]-'a']++;
}
int cnt =0;
while(1){
cnt = 0;
for(int i =0; i<26; i++){
if(savechar[i]!=0){
savechar[i]--;
char c = i+'a';
string t(1,c);
res += t;
cnt++;
}
}
if(cnt==0) return res;
cnt =0;
for(int i =25; i>=0; i--){
if(savechar[i]!=0){
savechar[i]--;
char c = i+'a';
string t(1,c);
res += t;
cnt++;
}
}
if(cnt==0) return res;
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1967. Number of Strings That Appear as Substrings in Word.cpp (0) | 2021.10.06 |
---|---|
1089. Duplicate Zeros.cpp (0) | 2021.10.06 |
1630. Arithmetic Subarrays.cpp (0) | 2021.10.06 |
1309. Decrypt String from Alphabet to Integer Mapping.cpp (0) | 2021.10.05 |
1827. Minimum Operations to Make the Array Increasing.cpp (0) | 2021.10.05 |