【leetcode】上升下降字符串

 

char * sortString(char * s){
    int hash[26]={0};
    int len = strlen(s);
    int i,pst=0;
    for (i=0; i<len; i++) hash[s[i] - 'a']++;
    while(pst < len)
    {
        for (i=0; i<26; i++)
        {    
            if (hash[i]) {
                s[pst++]=i+'a';
                hash[i]--;
            }
        }
        for (i=25; i>=0; i--)
        {    
            if (hash[i]) {
                s[pst++]=i+'a';
                hash[i]--;
            }
        }        
    }
    return s;
}

 

posted @ 2020-09-25 17:43  温暖了寂寞  阅读(163)  评论(0编辑  收藏  举报