diff --git a/product-of-array-except-self/aa601.py b/product-of-array-except-self/aa601.py new file mode 100644 index 000000000..cfd7ab4d9 --- /dev/null +++ b/product-of-array-except-self/aa601.py @@ -0,0 +1,17 @@ +#시간복잡도: O(n), 공간복잡도 : O(n) + +class Solution: + def productExceptSelf(self, nums: list[int]) -> list[int] : + a = [1] * len(nums) + for n in range(len(nums) - 1) : + a[n + 1] = a[n] * nums[n] + + b = [1] * len(nums) + for n in range(len(nums) - 1, 0, -1) : + b[n - 1] = b[n] * nums[n] + + c = [1] * len(nums) + for n in range(len(nums)) : + c[n] = a[n] * b[n] + return c + diff --git a/reverse-bits/aa601.py b/reverse-bits/aa601.py new file mode 100644 index 000000000..adb619f25 --- /dev/null +++ b/reverse-bits/aa601.py @@ -0,0 +1,10 @@ +#시간복잡도 : O(1), 공간복잡도 : O(1) + +class Solution: + def reverseBits(self, n: int) -> int: + ret = 0 + for i in range(32) : + ret = (ret << 1 | (n & 1)) + n >>= 1 + return (ret) + diff --git a/two-sum/aa601.py b/two-sum/aa601.py new file mode 100644 index 000000000..d5e9875d6 --- /dev/null +++ b/two-sum/aa601.py @@ -0,0 +1,9 @@ +#시간복잡도 : O(n^2), 공간복잡도 : O(1) + +class Solution: + def twoSum(self, nums: list[int], target: int) -> list[int]: + for i in range(len(nums) - 1): + for k in range(i + 1, len(nums)): + if (nums[i] + nums[k] == target): + return ([i, k]) +