[小米OJ] 11. 构建短字符串

思路

排序后对两个字符串遍历

function solution(line) {
    var str = line.split(" ");
    var str1 = str[0].split("").sort();
    var str2 = str[1].split("").sort();
    var i = 0,
        j = 0;
    while (j < str2.length && i < str1.length) {
        if (str1[i] == str2[j]) {
            i++;
            j++;
        } else if (str1[i] < str2[j]) {
            break;
        } else {
            j++;
        }
    }
    return i < str1.length ? false + "" : true + "";
}

 

[小米OJ] 11. 构建短字符串

上一篇:android 8未知来源app安装


下一篇:Android studio的错误:radle sync failed: Cause: failed to find target android-21 :