成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Is Subsequence

liaosilzu2007 / 1623人閱讀

摘要:題目鏈接只要里面當(dāng)前的字符可以和里的字符匹配,的就很長(zhǎng),用字典存起來(lái)很大,用

Is Subsequence

題目鏈接:https://leetcode.com/problems...

greedy, 只要s里面當(dāng)前的字符可以和t里的字符匹配,s的index就+1

public class Solution {
    public boolean isSubsequence(String s, String t) {
        // 2 points, greedy
        int i = 0, j = 0;
        
        while(i < s.length() && j < t.length()) {
            if(s.charAt(i) == t.charAt(j)) i++;
            j++;
        }
        
        return i == s.length();
    }
}

follow up: string很長(zhǎng),用字典存起來(lái)
dict很大,用trie

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/66606.html

相關(guān)文章

  • [LintCode] Longest Increasing Subsequence

    Problem Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return the length of the LIS. Clarification Whats the definition of longest increasing subsequence?...

    Flands 評(píng)論0 收藏0
  • [LeetCode/LintCode] Is Subsequence

    Problem Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) ...

    terasum 評(píng)論0 收藏0
  • leetcode392. Is Subsequence

    摘要:題目要求如何判斷字符串是否是字符串的一個(gè)子序列。子序列是指中的字母均按照相對(duì)位置存在于中,比如是的一個(gè)子序列,但是就不是的一個(gè)子序列??梢钥吹轿覀兡軌蛘业揭粋€(gè)合法的序列,使得當(dāng)前字母的起始下標(biāo)始終大于上一個(gè)字母的下標(biāo)。 題目要求 Given a string s and a string t, check if s is subsequence of t. You may assum...

    youkede 評(píng)論0 收藏0
  • leetcode376. Wiggle Subsequence

    摘要:題目要求扭動(dòng)序列是指數(shù)組中的相鄰兩個(gè)元素的差保證嚴(yán)格的正負(fù)交替,如數(shù)組中相鄰兩個(gè)元素的差為,滿足扭動(dòng)序列的要求?,F(xiàn)在要求從一個(gè)數(shù)組中,找到長(zhǎng)度最長(zhǎng)的扭動(dòng)子序列,并返回其長(zhǎng)度。即前一個(gè)元素和當(dāng)前元素構(gòu)成下降序列,因此代碼如下 題目要求 A sequence of numbers is called a wiggle sequence if the differences between ...

    CoffeX 評(píng)論0 收藏0
  • LeetCode[300] Longest Increasing Subsequence

    摘要:再用二分法找當(dāng)前值應(yīng)該在排好序的數(shù)組中的插入位置。因?yàn)橐业氖亲铋L(zhǎng)的序列,所以每次將排好序的數(shù)組中替換成已經(jīng)排好序的,會(huì)能保證得到的結(jié)果是最長(zhǎng)的。保證升序相等也要替換這個(gè)值 LeetCode[300] Longest Increasing Subsequence Given an unsorted array of integers, find the length of longe...

    blankyao 評(píng)論0 收藏0
  • [LeetCode] 300. Longest Increasing Subsequence

    Problem Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7...

    luckyyulin 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<