LeetCode 32 - Longest Valid Parentheses
題目
題目連結:https://leetcode.com/problems/longest-valid-parentheses/
給定一個只包含 '(' 和 ')' 的字串 s,找到最長的合法括號子字串。
範例說明
Example 1:
1 | Input: "(()" |
Example 2:
1 | Input: ")()())" |
題目連結:https://leetcode.com/problems/longest-valid-parentheses/
給定一個只包含 '(' 和 ')' 的字串 s,找到最長的合法括號子字串。
1 | Input: "(()" |
1 | Input: ")()())" |
題目連結:https://leetcode.com/problems/substring-with-concatenation-of-all-words/
給定一個字串 s 和一個 words 陣列,words 內包含長度一樣的單詞。
找到所有的子字串的開頭索引值,子字串必須是 words 中的每一個單詞各出現一次的連接字串。
1 | Input: |
1 | Input: |
題目連結:https://leetcode.com/problems/reverse-nodes-in-k-group/
給定一個 Linked List(以下簡稱串列),以每 k 個節點為一段做反轉。
保證 k > 0 且 k <= 串列長度,如果剩下的一段長度不足 k 則不需要反轉。
Given this linked list: 1->2->3->4->5
For k = 2, you should return: 2->1->4->3->5
For k = 3, you should return: 3->2->1->4->5
題目連結:https://leetcode.com/problems/merge-k-sorted-lists/
合併 k 個已排序好的鏈結串列成一個排序好的鏈結串列。
1 | Input: |
題目連結:https://leetcode.com/problems/regular-expression-matching/
給一個字串 s 和樣板(pattern) p,實作支援 . 和 * 的 regular expression。
1 | '.' Matches any single character. 匹配一個任一字元。 |
計算 s 是否匹配 p。
1 | Input: |
1 | Input: |
題目連結:https://leetcode.com/problems/median-of-two-sorted-arrays/
給定兩個排序好的序列 nums1 和 nums2,長度分別為 m 和 n。
找到兩個序列的中位數。
Example 1
1 | nums1 = [1, 3] |
Example 2
1 | nums1 = [1, 2] |
題目連結:https://leetcode.com/problems/freedom-trail/
給定一個環狀的字串 ring,再給一個字串 key,要求利用 ring 在最少步數內拼出字串 key。
一開始指標在字串 ring 的第一個字元上,將指標順時鐘或是逆時鐘動一格算是一步。當指標所指的字元等於你要拼的 key 中的字元,你還必須花一步來按下確認按鈕。