[여름방학 2주차] - 김예경#58
Open
vss121 wants to merge 6 commits intoCBNU-Nnet:mainfrom
Hidden character warning
The head ref may contain hidden characters: "\uae40\uc608\uacbd/2\uc8fc\ucc28"
Open
Conversation
alirz-pixel
reviewed
Jul 11, 2022
김예경/1225 이상한 곱셈.py
Outdated
Collaborator
There was a problem hiding this comment.
와... 수식화하셔서 푸신건가요???
저는 이중 for문을 이용하여 각 문자끼리 곱한 것을 ans 에 더해주는 식으로 했는데,
정말 소릅돋는 풀이었습니다 ㄷㄷㄷ
alirz-pixel
reviewed
Jul 11, 2022
김예경/11478 서로 다른 부분 문자열의 개수.py
Outdated
Collaborator
There was a problem hiding this comment.
python의 slicing이랑 set을 이용하여 푸셨군요!!
하나 아쉬운 점이 있다면,
arr 을 set으로 선언하신 후, set의 add함수를 이용하여 한번에 구할 수 있습니다!
코드 확인하기
s = input()
s_length = len(s)
ans_set = set()
for i in range(s_length):
for j in range(i, s_length):
ans_set.add(s[i:j + 1])
print(len(ans_set))
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
😀 PR을 올리기 전 준비
🤩 이번주 문제
이상한 곱셈 Bronze2
서로 다른 부분 문자열의 개수 Silver3
문자열 압축 lv.1
🧑💻 어떻게 푸셨나요?
이상한 곱셈
처음에 그냥 단순하게 이중 반복문으로 푸니 시간초과가 나서
각 자리의 수를 list에 넣은 다음
1×3 + 1×4 + 2×3 + 2×4 + 1×3 + 1×4를 인수분해하면(1+2+1)x(3+4)임을 이용해서sum(A)xsum(B)로 구하였습니다.서로 다른 부분 문자열의 개수
반복문으로 모든 문자열을 구해서 list에 넣고 list를 set로 바꾸어 중복을 제거한 후 개수를 구하였습니다.
문자열 압축
s(입력받은 문자열)을 최소 1글자에서 최대 len(s)//2 글자 단위로 자르는 경우가 있겠고,각각의 경우에 대해서
ss(압축된 문자열)을 구해서 문자열 길이를 저장할 list에 집어넣었습니다.temp(비교할 가장 앞 문자열 한 단위)를 뒤에 있는 문자열 한 단위씩 순서대로 비교해가면서 개수를 증가시키고 달라지는 순간에ss에 붙이는데,마지막에 새롭게 시작하는 문자는
temp와cnt변수에 저장만 되고 끝나기 때문에 따로ss에 붙였습니다.✍️ 질문을 적어주세요.
.
📖 참고 사항
.