Leetcode-791 Custom Sort String(自定义字符串排序)
发布时间:2020-12-14 04:14:30 所属栏目:大数据 来源:网络整理
导读:1 int Bible[ 30 ]; 2 3 bool cmp( char a, char b) 4 { 5 // printf("%d %dn",a,b); 6 return Bible[a- ‘ a ‘ ] = Bible[b- ‘ a ‘ ] ? 0 : 1 ; // -97 7 } 8 9 class Solution 10 { 11 public : 12 string customSortString( string S, string T) 13 {
1 int Bible[30]; 2 3 bool cmp(char a,char b) 4 { 5 // printf("%d %dn",a,b); 6 return Bible[a-‘a‘] >= Bible[b-‘a‘] ? 0 : 1;//-97 7 } 8 9 class Solution 10 { 11 public: 12 string customSortString(string S,string T) 13 { 14 memset(Bible,0,sizeof(Bible)); 15 int layer = 1; 16 for(auto c:S) 17 { 18 Bible[c-‘a‘] = layer ++; 19 } 20 sort(T.begin(),T.end(),cmp); 21 return T; 22 } 23 }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |