-
-
Notifications
You must be signed in to change notification settings - Fork 245
[Jay-Mo-99] Week 6 #898
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
[Jay-Mo-99] Week 6 #898
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9f9e2b
Solve: valid-parentheses
Jay-Mo-99 75c1b83
Check the git status
Jay-Mo-99 e7f6aea
Change the commment
Jay-Mo-99 ffd6b99
Merge branch 'DaleStudy:main' into main
Jay-Mo-99 639f73f
Solve: Container with most water
Jay-Mo-99 3af0cab
Merge branch 'DaleStudy:main' into main
Jay-Mo-99 727931f
Analyze: Design add and search words data structure
Jay-Mo-99 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,57 @@ | ||
#해석 | ||
#매개변수 string s의 각 character인 c 가 open bracket이면 temp 리스트에 추가한다. | ||
#c가 close bracket이면 temp의 마지막 element와 짝이 맞는지 검사한다. 짝이 아니거나 temp에 아무 요소도 없으면 return false | ||
#검사 이후 temp에 잔여 요소가 남아있으면 짝이 맞지 않았다는 뜻이니 return false, 아닐 경우 return true | ||
# | ||
|
||
#Big O | ||
#- N: 문자열 s의 길이 | ||
|
||
#Time Complexity: O(N) = O(N) + O(1) | ||
#- for c in s : string s의 character의 수 만큼 진행된다. -> O(N) | ||
#-temp.append(c), temp.pop() : 리스트 연산은 상수 취급 -> O(1) | ||
|
||
#Space Complexity: O(N) | ||
#- temp : list temp은 최대 string s의 character수 만큼 요소를 저장할 가능성이 있다. | ||
|
||
|
||
class Solution(object): | ||
def isValid(self, s): | ||
""" | ||
:type s: str | ||
:rtype: bool | ||
""" | ||
temp = [] | ||
for c in s: | ||
#If c is Open bracket, append to the list | ||
if (c == "(") or (c=="{") or (c=="["): | ||
temp.append(c) | ||
#If C is Close bracket, Check the close bracket pairs with last elememt of temp list | ||
else: | ||
#There's no element in the tmep, Return false | ||
if(len(temp)==0): | ||
return False | ||
|
||
if(c==")") and (temp.pop()=="("): | ||
continue | ||
if(c=="}") and (temp.pop()=="{"): | ||
continue | ||
if(c=="]") and (temp.pop()=="["): | ||
continue | ||
else: | ||
return False | ||
|
||
#After loop, Check temp is empty or not. | ||
#If all c of s is pairs each other, the temp list is empty. | ||
if (len(temp) == 0) : | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.
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.
안녕하세요, @Jay-Mo-99 님,
개인 선호 차이인것 같습니다만, 아래와 같이 마무리해도 좋을것 같습니다. 😀
또는
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에 바로 조건문을 입력하면 코드 수를 줄일수 있군요. if~else 구조 대신에 자주 사용해보도록 해봐야 겠어요. 피드백 감사합니다.