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

資訊專欄INFORMATION COLUMN

[LintCode] Split String

Riddler / 1430人閱讀

Problem

Give a string, you can choose to split the string after one character or two adjacent characters, and make the string to be composed of only one character or two characters. Output all possible results.

Example

Given the string "123"
return [["1","2","3"],["12","3"],["1","23"]]

Solution
public class Solution {
    /*
     * @param : a string to be split
     * @return: all possible split string array
     */
    public List> splitString(String s) {
        // write your code here
        List> res = new ArrayList<>();
        if (s == null) return res;
        if (s.length() == 0) {
            res.add(new ArrayList());
            return res;
        }
        dfs(s, 0, new ArrayList(), res);
        return res;
    }
    public void dfs(String s, int index, List cur, List> res) {
        if (index >= s.length()) {
            res.add(new ArrayList(cur));
            return;
        }
        int i = index;
        while (i <= index+1 && i < s.length()) {
            cur.add(s.substring(index, i+1));
            dfs(s, i+1, cur, res);
            cur.remove(cur.size()-1);
            i++;
        }
    }
}

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

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

相關文章

  • [LintCode/LeetCode] Binary Tree Serialization

    摘要:這里要注意的是的用法。所以記住,用可以從自動分離出數組。跳過第一個元素并放入數組最快捷語句建立的用意記錄處理過的結點并按處理所有結點和自己的連接下面先通過判斷,再修改的符號的順序,十分巧妙更輕便的解法 Problem Design an algorithm and write code to serialize and deserialize a binary tree. Writin...

    keithyau 評論0 收藏0
  • [LintCode] Missing String

    Problem Given two strings, you have to find the missing string. Example Given a string str1 = This is an exampleGiven another string str2 = is example Return [This, an] Solution public class Solution ...

    IamDLY 評論0 收藏0
  • [LintCode] Valid Number

    摘要:兩種情況有無,如上所示。如何判斷是否只有一個之后的長度小于等于。注意,為空只有在字符串最末位或者只有都是錯誤的。規則若字符串首位為,取其,然后將應用轉換為數組,逐位判斷字符,出現將置如已經置,再次出現則直接返回。 Problem Validate if a given string is numeric. Example 0 => true 0.1 => true abc =>...

    since1986 評論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] Simplify Path [字符串操作]

    摘要:,可以用函數去掉所有,然后多考慮一個中間為空的。關于語句的一個特點我們對和其實都是不做操作,然而,兩個可以都,但是不能都不做操作。像這樣這樣這兩個就都會等價于下一個就會出錯。 Problem Given an absolute path for a file (Unix-style), simplify it. Example /home/, => /home //去掉末尾的slash...

    leanxi 評論0 收藏0

發表評論

0條評論

Riddler

|高級講師

TA的文章

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