Missing String

http://www.lintcode.com/zh-cn/problem/missing-string/

public class Solution {
    /*
     * @param : a given string
     * @param : another given string
     * @return: An array of missing string
     */
    public List missingString(String str1, String str2) {
        // Write your code here
        List res = new ArrayList<>();
        String[] split1 = str1.trim().split(" ");
        String[] split2 = str2.trim().split(" ");
        for (String temp : split1) {
            res.add(temp);
        }
        for (String temp : split2) {
            //测试一下就明白为什么了
            while (true) {
                int i = res.indexOf(temp);
                if (i >= 0) {
                    res.remove(temp);
                } else {
                    break;
                }
            }
        }
        return res;
    }
};

你可能感兴趣的:(Missing String)