Skip to content

Commit

Permalink
Merge pull request #798 from aa601/main
Browse files Browse the repository at this point in the history
[yeoju] Week 3
  • Loading branch information
SamTheKorean authored Dec 29, 2024
2 parents dc26587 + ba84e6d commit 4cf7b2c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions product-of-array-except-self/aa601.py
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions reverse-bits/aa601.py
Original file line number Diff line number Diff line change
@@ -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)

9 changes: 9 additions & 0 deletions two-sum/aa601.py
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit 4cf7b2c

Please sign in to comment.