https://leetcode.com/problems/longest-palindrome/ Solution Palindrome: 回文 Time Complexity: O(len(s)) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) ...
https://leetcode.com/problems/determine-if-two-strings-are-close/ Solution Time Complexity: O(len(word1)) Space Complexity: O(1) ※ 英文字母只有26個,所以 sort 在時間上將會花費 O(26 * log(26)) = O(1) 在 Space Complexity ...
https://leetcode.com/problems/determine-if-string-halves-are-alike/ Solution 注意: s[:len(s) // 2] s[:len(s) / 2] ( len(s) / 2 不是整數,不能作為 index ) Time Complexity: O(len(s)) Space Complexity: O(1) (The i ...
$$ \mathop{arg\_min}\limits_{x \in S} := \{ x \in S : f(s) \geq f(x) \text{for all } s \in S \} $$ $$ \mathop{arg\_max}\limits_{x \in S} := \{ x \in S : f(s) \leq f(x) \text{for all } s \in S \} $$
https://leetcode.com/problems/linked-list-cycle-ii/ First Solution Time Complexity: O(length(list)) Space Complexity: O(length(list)) (The input and output generally do not count towards the space com ...
https://leetcode.com/problems/middle-of-the-linked-list/ Solution *fast 的速度是 *slow 的兩倍 Time Complexity: O(len(head)) Space Complexity: O(1) (The input and output generally do not count towards the spa ...
https://leetcode.com/problems/pascals-triangle/ Solution Time Complexity: O((1 + numRows) * numRows / 2) = O(numRows ^ 2) Space Complexity: O(1) (The input and output generally do not count towards th ...
https://leetcode.com/problems/reshape-the-matrix/ Solution Time Complexity: O(r * c) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) new_mat = [[0 fo ...
https://leetcode.com/problems/merge-two-sorted-lists/ Solution Time Complexity: O(length(list1) + length(list2)) Space Complexity: O(1) class Solution { public: ListNode* mergeTwoLists(ListNode* list1 ...
https://leetcode.com/problems/intersection-of-two-arrays-ii/ Solution Time Complexity: O(len(nums1) + len(nums2)) Space Complexity: O(len(nums1) + len(nums2)) class Solution: def intersect(self, nums1 ...