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 ...
Arguments of the Maxima/Minima $$ \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) \ ...
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 ...
https://leetcode.com/problems/isomorphic-strings/ Solution Time Complexity: O(s.length()) Space Complexity: O(s.length()) class Solution { public: bool isIsomorphic(string s, string t) { std::map<c ...
https://leetcode.com/problems/merge-sorted-array/ First Solution 從尾到頭逆著做回來 Time Complexity: O(m + n) Space Complexity: O(1) class Solution { public: void merge(vector& nums1, int m, vector& nu ...