Leetcode-791 Custom Sort String(自定义字符串排序)
1 int Bible[30]; 2 3 bool cmp(char a,char b) 4 { 5 // printf("%d %d\n",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 };