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 ...
Hash table in C++ 初始化 std::set<template> s; std::set<template> s{…}; template arr = {…}; std::set<template> s(arr, arr + {length of arr}); — std::map<template_ke ...
for(range_declaration : range_expression){ loop_statement } 範例 用 range based for loop 存取 vector for(int y : x)cout << y << " "; cout << endl;