Solution 1 Time complexity is O(n). Space complexity is O(1). Solution 2 Time complexity is O(n). Space complexity is O(1).
Category Archives: Uncategorized
LeetCode 242 – Python 3 (Week 06 – 07)
Solution 1 Time complexity is O(nlogn). Space complexity is O(n). Solution 2 Time complexity is O(nlogn). Space complexity is O(n). Solution 3 Time complexity is O(n). Space complexity is O(1).
LeetCode 237 – Python 3 (Week 06 – 06)
Solution 1 class Solution: def deleteNode(self, node): “”” :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. “”” node.val = node.next.val node.next = node.next.next Time and space complexity are both O(1).
LeetCode 217 – Python 3 (Week 06 – 05)
Solution 1 Time complexity is O(nlogn). Space complexity is O(1). Solution 2 Time complexity is O(n). Space complexity is O(1).
*LeetCode 204 – Python 3 (Week 06 – 04)
Solution 1 *Time complexity is O(nloglogn). Space complexity is O(n)
LeetCode 202 – Python 3 (Week 06 – 03)
Solution 1 Time complexity is O(1). Space complexity is O(1). Solution 2 Time complexity is O(1). Space complexity is O(1). How to calculate the complexity? Input is a positive integer. Assume it is 32 bit. So we calculate maximum of 10 digits. Assume it is maximum 10 digits 9^2 +9^2…. The sum is 10*81 = …
LeetCode 191 – Python 3 (Week 06 – 02)
Solution 1 (Same to No. 190) Time complexity is O(1). Space complexity is O(1). Solution 2 Time complexity is O(1). Space complexity is O(1).
LeetCode 190 – Python 3 (Week 06 – 01)
0 & 1 = 0, 1 & 1 = 1 -> xxxxxxy & 1 = y Solution 1 Time complexity is O(1). Space complexity is O(1).
LeetCode 189 – Python 3 (Week 05 – 18)
Although I spend a lot of time in Cyclic Replacements method, I still couldn’t write the right program. Solution 1 Time complexity is O(n). Space complexity is O(n). Solution 2 Time complexity is O(n). Space complexity is O(1).
LeetCode 172 – Python 3 (Week 05 – 17)
Solution 1 Time complexity is O(log5). Space complexity is O(1).