-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #798 from aa601/main
[yeoju] Week 3
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
|