Leetcode in Java && Oracle
419 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
Leetcode in Java && Oracle
image_2021-11-09_15-12-58.png
image_2021-11-09_15-29-43.png
57.8 KB
#updated

class Solution {
public String customSortString(String order, String s) {
StringBuilder res=new StringBuilder();
int[] arr=new int[26];

for(int i=0; i<s.length(); i++){
arr[s.charAt(i)-'a']++;
}

for(int i=0; i<order.length(); i++){
while(arr[order.charAt(i)-'a']>0){
res.append(order.charAt(i));
arr[order.charAt(i)-'a']--;
}
}

for(int i=0; i<26; i++){
while(arr[i]>0){
res.append((char) (i+'a'));
arr[i]--;
}
}

return res.toString();
}
}

p.s.: better runtime than previous one)