class Solution {
int[] w = new int[30];
public String customSortString(String order, String s) {
for (int i =0 ; i < 26;i ++) {
w[i] = 30;
}
for (int i = 0; i < order.length(); i++) {
int chI = order.charAt(i) - 'a';
w[chI] = i;
}
char[] chars = s.toCharArray();
sort(chars);
return new String(chars);
}
public void sort(char[] ch) {
int n = ch.length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (w[ch[i] - 'a'] < w[ch[j] - 'a']) {
swap(ch, i, j);
}
}
}
}
public void swap(char[] ch, int i, int j) {
char temp = ch[i];
ch[i] = ch[j];
ch[j] = temp;
}
}
标签:ch,自定义,791,int,char,++,排序,String
From: https://www.cnblogs.com/eiffelzero/p/16886456.html