成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

408. Valid Word Abbreviation

DangoSky / 2369人閱讀

Given s = "internationalization", abbr = "i12iz4n":

Return true.

Given s = "apple", abbr = "a2e":

Return false.
public class Solution {
    public boolean validWordAbbreviation(String word, String abbr) {
        int len = 0;
        int i = 0, j = 0;
        
        while(i < word.length() && j < abbr.length()){
            if(word.charAt(i) == abbr.charAt(j)){
                i++;
                j++;
                continue;
            }
            if(abbr.charAt(j) <= "0" || abbr.charAt(j) > "9"){
                return false;
            }
            int start = j;
            while(j< abbr.length() && abbr.charAt(j) >= "0" && abbr.charAt(j) <= "9"){
                j++;
            }
            int num = Integer.valueOf(abbr.substring(start, j));
            i += num;
        }
        
        return i == word.length() && j == abbr.length();
    }
}

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

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/66924.html

相關(guān)文章

  • [LeetCode] 408. Valid Word Abbreviation

    Problem Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation. A string such as word contains only the following valid abbreviations: [word...

    zone 評(píng)論0 收藏0
  • Word Abbreviation

    摘要:鏈接注意第一個(gè)數(shù)字是的情況,這種也是不合法的。還有一個(gè)注意的就是要想和有相同的縮寫,長(zhǎng)度必須和它相同,所以只保留長(zhǎng)度相同的。注意剪枝,當(dāng)前長(zhǎng)度已經(jīng)超過(guò)就不需要繼續(xù)了。二進(jìn)制的做法是這樣的,先對(duì)字典里面的單詞進(jìn)行處理。 Valid Word Abbreviation 鏈接:https://leetcode.com/problems... 注意第一個(gè)數(shù)字是0的情況,[a, 01]這種也是不...

    Y3G 評(píng)論0 收藏0
  • Unique Word Abbreviation LC解題記錄

    摘要:題目?jī)?nèi)容這題也是鎖住的,通過(guò)率只有左右。另外,字典里面只有兩個(gè)的時(shí)候,也是返回。最后再說(shuō)兩句距離上一篇文章過(guò)了一段時(shí)間了,這段時(shí)間搬家再適應(yīng)新環(huán)境,解決心理問(wèn)題。 題目?jī)?nèi)容 An abbreviation of a word follows the form . Below are some examples of word abbreviations: a) it ...

    curried 評(píng)論0 收藏0
  • 320. Generalized Abbreviation

    摘要:題目鏈接要輸出所有的結(jié)果,標(biāo)準(zhǔn)思路。也可以做,保留為,改為數(shù)字的為,然后結(jié)果就是這么多,每個(gè)數(shù)學(xué)遍歷一遍求對(duì)應(yīng)的即可。 320. Generalized Abbreviation 題目鏈接:https://leetcode.com/problems... 要輸出所有的結(jié)果,backtracking標(biāo)準(zhǔn)思路。 public class Solution { public List...

    yangrd 評(píng)論0 收藏0
  • 320. Generalized Abbreviation and 22. Generate Par

    320 Generalized Abbreviation public class Solution { public List generateAbbreviations(String word) { List res = new ArrayList(); backtrack(res, word, 0, , 0); return res; ...

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

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

0條評(píng)論

閱讀需要支付1元查看
<