-
-
Notifications
You must be signed in to change notification settings - Fork 195
[yyyyyyyyyKim] WEEK 02 solutions #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7bc0b19
valid-anagram
yyyyyyyyyKim 306ac37
valid-anagram solution
yyyyyyyyyKim abda699
climbing-stairs solution
yyyyyyyyyKim e7d4234
climbing-stairs solution 개행문자추가
yyyyyyyyyKim 6e9b6df
climbing-stairs solution 개행문자
yyyyyyyyyKim 13977bc
climbing-stairs solution 개행문자
yyyyyyyyyKim af92506
climbing-stairs solution 개행문자
yyyyyyyyyKim 90bea1d
product-of-array-except-self solution
yyyyyyyyyKim 5901324
3sum solution
yyyyyyyyyKim ae0d55d
validate-binary-search-tree solution
yyyyyyyyyKim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,36 @@ | ||
class Solution: | ||
def threeSum(self, nums: List[int]) -> List[List[int]]: | ||
|
||
answer = [] | ||
|
||
# 정렬 | ||
nums.sort() | ||
|
||
for i in range(len(nums)-2): | ||
# i 중복제거 | ||
if i > 0 and nums[i] == nums[i - 1]: | ||
continue | ||
|
||
left = i+1 | ||
right = len(nums)-1 | ||
|
||
while left < right: | ||
if nums[i] + nums[left] + nums[right] == 0: | ||
answer.append([nums[i],nums[left],nums[right]]) | ||
|
||
# left 중복제거 | ||
while left < right and nums[left] == nums[left+1]: | ||
left += 1 | ||
# right 중복제거 | ||
while left < right and nums[right] == nums[right-1]: | ||
right -= 1 | ||
|
||
left += 1 | ||
right -= 1 | ||
|
||
elif nums[i] + nums[left] + nums[right] < 0: | ||
left += 1 | ||
else: | ||
right -= 1 | ||
|
||
return answer |
This file contains hidden or 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,12 @@ | ||
class Solution: | ||
def climbStairs(self, n: int) -> int: | ||
|
||
if n <= 3: | ||
return n | ||
|
||
a, b = 1, 2 | ||
|
||
for i in range(3,n+1): | ||
a, b = b, a+b | ||
|
||
return b |
This file contains hidden or 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,16 @@ | ||
class Solution: | ||
def productExceptSelf(self, nums: List[int]) -> List[int]: | ||
|
||
answer = [1]*len(nums) | ||
|
||
left = 1 | ||
for i in range(len(nums)): | ||
answer[i] *= left | ||
left *= nums[i] | ||
|
||
right = 1 | ||
for i in range(len(nums)-1,-1,-1): | ||
answer[i] *= right | ||
right *= nums[i] | ||
|
||
return answer |
This file contains hidden or 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,6 @@ | ||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
|
||
if sorted(s) == sorted(t): | ||
return True | ||
return False | ||
This file contains hidden or 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,19 @@ | ||
# Definition for a binary tree node. | ||
# class TreeNode: | ||
# def __init__(self, val=0, left=None, right=None): | ||
# self.val = val | ||
# self.left = left | ||
# self.right = right | ||
class Solution: | ||
def isValidBST(self, root: Optional[TreeNode]) -> bool: | ||
|
||
# 깊이우선탐색(dfs), 재귀 | ||
def dfs(node, min_val, max_val): | ||
if not node: | ||
return True | ||
if not (min_val < node.val < max_val): | ||
return False | ||
return (dfs(node.left, min_val, node.val) and | ||
dfs(node.right, node.val, max_val)) | ||
|
||
return dfs(root, float('-inf'), float('inf')) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return sorted(s) == sorted(t);
한줄로 가능하지 않을까요?