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.
ExampleGiven the string "123"
return [["1","2","3"],["12","3"],["1","23"]]
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
摘要:這里要注意的是的用法。所以記住,用可以從自動分離出數組。跳過第一個元素并放入數組最快捷語句建立的用意記錄處理過的結點并按處理所有結點和自己的連接下面先通過判斷,再修改的符號的順序,十分巧妙更輕便的解法 Problem Design an algorithm and write code to serialize and deserialize a binary tree. Writin...
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 ...
摘要:兩種情況有無,如上所示。如何判斷是否只有一個之后的長度小于等于。注意,為空只有在字符串最末位或者只有都是錯誤的。規則若字符串首位為,取其,然后將應用轉換為數組,逐位判斷字符,出現將置如已經置,再次出現則直接返回。 Problem Validate if a given string is numeric. Example 0 => true 0.1 => true abc =>...
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...
摘要:,可以用函數去掉所有,然后多考慮一個中間為空的。關于語句的一個特點我們對和其實都是不做操作,然而,兩個可以都,但是不能都不做操作。像這樣這樣這兩個就都會等價于下一個就會出錯。 Problem Given an absolute path for a file (Unix-style), simplify it. Example /home/, => /home //去掉末尾的slash...
閱讀 2471·2021-11-17 09:33
閱讀 758·2021-11-04 16:13
閱讀 1329·2021-10-14 09:50
閱讀 692·2019-08-30 15:53
閱讀 3657·2019-08-30 14:18
閱讀 3268·2019-08-30 14:14
閱讀 2093·2019-08-30 12:46
閱讀 3178·2019-08-26 14:05