class Solution {
    public String maximumNumber(String num, int[] change) {
        StringBuilder str = new StringBuilder();
        int flag = 0;
        int i = 0;
        for (; i < num.length(); i++) {
            int n = num.charAt(i) - '0';
            if (n > change[n] && flag == 1) {
                break;
            }
            if (n < change[n]) {
                str.append(change[n]);
                flag = 1;
            }else{
                str.append(n);
            }
        }
        return str + num.substring(i);
    }
}
//runtime:12 ms
//memory:39.3 MB
