国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LintCode] Missing String

IamDLY / 1636人閱讀

Problem

Given two strings, you have to find the missing string.

Example

Given a string str1 = This is an example
Given another string str2 = is example

Return ["This", "an"]

Solution
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[] s1 = str1.split(" ");
        String[] s2 = str2.split(" ");
        if (s1.length == s2.length) {
            return res;
        }
        //assume s1.length > s2.length
        if (s1.length < s2.length) {
            String[] temp = s1;
            s1 = s2;
            s2 = temp;
        }
        
        Set unique = new HashSet<>();
        
        //save the short string array in hashset
        for (String s: s2) {
            unique.add(s);
        }
        
        //check the long string array and put the missing strings in result
        for (String s: s1) {
            if (!unique.contains(s)) {
                res.add(s);
            }
        }
        
        return res;
    }
};

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/70943.html

相關文章

  • [LintCode] First Missing Positive

    摘要:找第一個缺失的正整數,只要先按順序排列好,也就是,找到第一個和不對應的數就可以了。注意數組的從開始,而正整數從開始,所以重寫排列的時候要注意換成,而就是從開始的數組中的元素。 Problem Given an unsorted integer array, find the first missing positive integer. Example Given [1,2,0] re...

    snifes 評論0 收藏0
  • [LintCode] Find the Missing Number [三種方法]

    摘要:求和相減是先求出到這個等差數列的和,再減去實際數組的和,就是缺失的數,第二種方法是,只要先按順序排列好,用二分法找到第一個和不相等的數就可以了。二分法求和相減法共個數,多加了一個異或法 Problem Given an array contains N numbers of 0 .. N, find which number doesnt exist in the array. Exa...

    liaoyg8023 評論0 收藏0
  • [LintCode/LeetCode] Set Mismatch

    Problem The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetit...

    Astrian 評論0 收藏0
  • [LeetCode/LintCode] Top K Frequent Words

    LeetCode version Problem Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, t...

    0x584a 評論0 收藏0
  • [LintCode/LeetCode] Word Break

    Problem Given a string s and a dictionary of words dict, determine if s can be break into a space-separated sequence of one or more dictionary words. Example Given s = lintcode, dict = [lint, code]. R...

    dunizb 評論0 收藏0

發表評論

0條評論

IamDLY

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<