Two Sum
Approach 1: Brute Force
class Solution |
$$
T(n)=O(n^2)
\
S(n)=O(1)
$$
Approach 2: One-pass Hash Table
class Solution |
$$
T(n)=O(n) \ S(n)=O(n)
$$
Runtime: 12 ms, faster than 94.28% of C++ online submissions for Two Sum.
Memory Usage: 10.4 MB, less than 32.76% of C++ online submissions for Two Sum.
Add Two Numbers
Approach 1: Elementary Math
/** |
$$
T(n)=O(max(m, n)) \ S(n)=O(max(m, n))
$$
Runtime: 40 ms, faster than 96.35% of C++ online submissions for Add Two Numbers.
Memory Usage: 19.1 MB, less than 61.79% of C++ online submissions for Add Two Numbers.
Longest Substring Without Repeating Characters
Approach 1: Sliding Window
class Solution |
$$
T(n)=O(n) \ S(n)=O(min(m, n))
$$
Runtime: 36 ms, faster than 49.65% of C++ online submissions for Longest Substring Without Repeating Characters.
Memory Usage: 16.1 MB, less than 60.63% of C++ online submissions for Longest Substring Without Repeating Characters.
Approach 2: Brute Force
class Solution |
$$
T(n)=O(n^2) \ S(n)=O(min(m, n))
$$
Runtime: 1148 ms, faster than 5.14% of C++ online submissions for Longest Substring Without Repeating Characters.
Memory Usage: 272 MB, less than 5.03% of C++ online submissions for Longest Substring Without Repeating Characters.