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

資訊專欄INFORMATION COLUMN

Is Subsequence

liaosilzu2007 / 1608人閱讀

摘要:題目鏈接只要里面當前的字符可以和里的字符匹配,的就很長,用字典存起來很大,用

Is Subsequence

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

greedy, 只要s里面當前的字符可以和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很長,用字典存起來
dict很大,用trie

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

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

相關文章

  • [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 評論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 評論0 收藏0
  • leetcode392. Is Subsequence

    摘要:題目要求如何判斷字符串是否是字符串的一個子序列。子序列是指中的字母均按照相對位置存在于中,比如是的一個子序列,但是就不是的一個子序列。可以看到我們能夠找到一個合法的序列,使得當前字母的起始下標始終大于上一個字母的下標。 題目要求 Given a string s and a string t, check if s is subsequence of t. You may assum...

    youkede 評論0 收藏0
  • leetcode376. Wiggle Subsequence

    摘要:題目要求扭動序列是指數組中的相鄰兩個元素的差保證嚴格的正負交替,如數組中相鄰兩個元素的差為,滿足扭動序列的要求。現在要求從一個數組中,找到長度最長的扭動子序列,并返回其長度。即前一個元素和當前元素構成下降序列,因此代碼如下 題目要求 A sequence of numbers is called a wiggle sequence if the differences between ...

    CoffeX 評論0 收藏0
  • LeetCode[300] Longest Increasing Subsequence

    摘要:再用二分法找當前值應該在排好序的數組中的插入位置。因為要找的是最長的序列,所以每次將排好序的數組中替換成已經排好序的,會能保證得到的結果是最長的。保證升序相等也要替換這個值 LeetCode[300] Longest Increasing Subsequence Given an unsorted array of integers, find the length of longe...

    blankyao 評論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 評論0 收藏0

發表評論

0條評論

liaosilzu2007

|高級講師

TA的文章

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