EX:
n = 3,
[
"((()))", "(()())", "(())()", "()(())", "()()()" ]
"((()))", "(()())", "(())()", "()(())", "()()()" ]
Output: 1->1->2->3->4->4
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Note that an empty string is also considered valid.
EX:
Input: "()[]{}"
Output: true
Input: "([)]"Output: false
Given a linked list, remove the n-th node from the end of list and return its head.
EX:
Given linked list: 1->2->3->4->5, and n = 2.
After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].Ans: [ [-1, 0, 0, 1], [-2, -1, 1, 2], [-2, 0, 0, 2] ]
[Ans: [-1, 0, 1], [-1, -1, 2] ]
Output: "fl" Input: ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among the input strings.
Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000
Input: "III" Output: 3
Input: "IV" Output: 4
Input: "IX" Output: 9
Input: "LVIII" Output: 58 Explanation: L = 50, V= 5, III = 3.
Input: "MCMXCIV" Output: 1994 Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
'.' Matches any single character. '*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lowercase letters a-z.p could be empty and contains only lowercase letters a-z, and characters like . or *. inorder = [9,3,15,20,7]3 / \ Ans: 9 20 / \ 15 7
postorder = [9,15,7,20,3]Ans: 3
/ \ 9 20 / \ 15 7
Output: trueInput: -121 Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
這題要我們實作一個將 string 換成 integer 的函數,類似 atoi 的功能。
EX:
Input: " -42"
Output: -42 Explanation: The first non-whitespace character is '-', which is the minus sign. Then take as many numerical digits as possible, which gets 42.
Input: 123 Output: 321
Output: "bab" Note: "aba" is also a valid answer.
nums2 = [2]
The median is 2.0
3 / \ 1 4 / 2 Output: [2,1,4,null,null,3] 2 / \ 1 4 / 3
/ \ / \
2 1 1 2
[1,2,1], [1,1,2]
Output: false
/ \ 1 4 / \ 3 6 Input: [5,1,4,null,null,3,6] Output: false Explanation: The root node's value is 5 but its right child's value is 4.
Output:
[
[1,null,3,2],
[3,2,null,1],
[3,1,null,null,2],
[2,1,3],
[1,null,2,null,3]
]
Explanation:
The above output corresponds to the 5 unique BST's shown below:
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3Output: 5
Explanation: Given n = 3, there are a total of 5 unique BST's: 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3
1 \ 2 / 3 Output: [1,3,2]
Output: ["255.255.11.135", "255.255.111.35"] Output: 5->4->3->2->1->NULL'B' -> 2 ... 'Z' -> 26input:
Output: 3 Explanation: It could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
Output: [ [2], [1], [1,2,2], [2,2], [1,2], [] ]
great / \ gr eat / \ / \ g r e at / \ a t
s2:
rgeat
/ \
rg eat
/ \ / \
r g e at
/ \
a tAns: True, 可以透過交換 s1 中 gr 的兩個子節點來將 s1 轉成 s2。
Ans: 3
Output: 7 -> 0 -> 8 , 342 + 465 = 807["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"] ]
Ans: 6
Ans: 1->2->3想法:
這雖然是一題 easy 的題目,但還蠻有意思的很值得練習,雖然要寫出來不難,但要寫得
簡潔也是需要一定程度的練習,尤其對指標的理解需要夠清晰。
[ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E'] ]
word = "ABCCED", return true.
Ans: 1->2->2->4->3->5
Ans: [[],[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]
4,5,6,7,0,1,2], target = 0