-
Notifications
You must be signed in to change notification settings - Fork 0
4-bishoe01 #19
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
4-bishoe01 #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // ๋ฌธ์ : 1839. Longest Substring Of All Vowels in Order | ||
| import Foundation | ||
|
|
||
| class Solution { | ||
| let vowels: [Character] = ["a", "e", "i", "o", "u"] | ||
| func longestBeautifulSubstring(_ word: String) -> Int { | ||
| // ๊ธธ์ด 5๋ณด๋ค ์๋ ์์ | ||
| guard word.count >= 5 else { | ||
| return 0 | ||
| } | ||
|
Comment on lines
+7
to
+10
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ฌ๊ธฐ guard๋ฌธ ๋๊ฒ ์ข์๋ฐ์!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ชจ์ผ ๊ธธ ์์ ๊น๋ํ๋ค
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sep037
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ง์์ .. ! |
||
| var previous: Character = "z" | ||
| var count = 0 | ||
| var answer = 0 | ||
|
Comment on lines
+11
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nil๋ก ์ํ์ ์ด์ ๊ฐ ์์๊น์?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+11
to
+13
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nil ์ฒดํฌ๋ก z๋ฅผ ํ์ ๊ฑฐ๊ตฐ์. ์ ๋ ํจ๋๊ตฐ๊ณผ ์ง๋ฌธ์ด ๋๊ฐ์ต๋๋ค. nil๋ก ์ํ์ ์ด์ ๊ฐ ์์๊น์ ?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bishoe01 ์ ๋ ๊ถ๊ธํด์ ํ ใ ใ ใ z๋ก ํ์ ์ด์ ๋?!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 222222 .!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์ ์ ์๋ฏ์ด |
||
| // ์ถ์์๋๋ฉด ๋ฌด์กฐ๊ฑด ์์์ a๊ฐ ๋์ด์ผํจ | ||
| for item in word { | ||
| // 'z'๋ ์ฌ์ค์ nil์ ๋ปํ๊ธฐ ์ํ ์ฝ๋ ('z'๊ฐ previous๋ผ๋ฉด ์ด๊ฑฐ ์๋ก previous๋ฅผ ์ฐพ์์ผํ๋ค๋ ๋ป) | ||
| if previous == "z" { | ||
| if item == "a" { | ||
| previous = item | ||
| } | ||
| // ์์์ ์ด ๋์ด์ผํ๋๋ฐ, a๊ฐ ์๋๋ฉด ๊ฑ ๋ ๋ ค๋ฒ๋ฆฌ๊ธฐ | ||
| else { | ||
| continue | ||
| } | ||
| } | ||
| if canGo(previous, item) { | ||
| count += 1 | ||
| previous = item | ||
| // print(item) | ||
| } | ||
|
Comment on lines
+26
to
+30
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ค ๊ฐ ์ ์๋์ง ์๋์ง ํจ์ํ๋ฅผ ํ์ จ๊ตฐ์
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ง์์ ์ฝ๊ฐ |
||
| else { | ||
| // ๋์ด u๊ฐ ์๋๋ผ๋ฉด ์ด๊ฒ ๋ค ์์ฑ์ด ์๋์ํ๋ผ 0 ์ฒ๋ฆฌ๊ฐ ๋์ด์ผํจ | ||
| if previous == "u" { | ||
| // print("HERE \(item) \(count)") | ||
| answer = max(answer, count) | ||
| } | ||
| // a๊ฐ ๋์์ ๋๊ฒผ์ผ๋ฉด ๊ทธ๋ฅ ๊ทธ๋๋ถํฐ ์นด์ดํ | ||
| if item == "a" { | ||
| previous = item | ||
| count = 1 | ||
| } | ||
| // ๊ทธ๊ฒ ์๋๋ผ๋ฉด "z"๋ฅผ ์ค์ ์ด๊ธฐํ๋๊ฒ๋ ํจ | ||
| else { | ||
| previous = "z" | ||
| count = 0 | ||
| } | ||
| } | ||
| } | ||
| // ๋์ ๊ฑธ๋ฆฌ์ง์๊ณ ๋๋๋ฒ๋ฆฌ๋ฉด ์นด์ดํ ์ด ์๋จ | ||
| if previous == "u" { | ||
| return max(answer, count) | ||
| } | ||
| else { | ||
| return answer | ||
| } | ||
| } | ||
|
Comment on lines
+26
to
+56
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๊น๋ํ๋ค์! ๋ฌธ์์ด ๊นจ์ก์ ๋๋ ๋ฃจํ ์ข ๋ฃํ์๋ง ๋ฌธ์์ด ๊ธธ์ด ๋น๊ตํด์ฃผ๋ฉด ๋๋ค์. ์ ์ด์ด์ดํ๋์ฝ๋ฉ์ผ๋ก U๋์ฌ๋๋ง๋ค ๋น๊ตํด์ฃผ๋ ๋นํจ์จ์ ์ธ ์ฝ๋ ์งฐ๋ต๋๋ค.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๊ธธ์ ์๋ ํ์ด (์ฌ๋ผ์ด๋ฉ ์๋์ฐ)๊ฐ ์ฐ ์ ์์ธ๊ฒ๊ฐ์์..! ์ ๋ ๋ง ๊ตฌํํ๋ฏ์ด ์ด๊ฒ์ ๊ฒ์ฐ๋ฌ๋ณธ๊ฑฐ๋ผ...! ์์ง ๊ฐ๊ธธ์ด๋จธ๋ค์.. ๐ |
||
|
|
||
| func canGo(_ previous: Character, _ current: Character) -> Bool { | ||
| let previousIdx = vowels.firstIndex(of: previous)! | ||
| let currentIdx = vowels.firstIndex(of: current)! | ||
| // ๊ฐ๊ฑฐ๋ ํ๋ ์ฐจ์ด ๋ ๋๋ง | ||
| if currentIdx - previousIdx <= 1 && currentIdx - previousIdx > -1 { | ||
| // print(previous, current) | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
Comment on lines
+59
to
+67
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ๋ถ๋ถ์ guard let prevIdx = vowels.firstIndex(of: previous),
let currIdx = vowels.firstIndex(of: current) else {
return false
}
return currIdx >= prevIdx && currIdx - prevIdx <= 1๋ก ์ค๋ณต์กฐ๊ฑด ์ ๊ฑฐํ๊ณ , guard let์ผ๋ก ์ต์ ๋ ๋ฐ์ธ๋ฉํด์ฃผ๋ฉด ์ด๋จ๊นํด์ ๋จ๊ฒจ๋ณด์์ต๋๋ค.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ฐ๋ฏธ๊ฐ guard let ๋ง์คํฐ ํ์ จ๊ตฐ๋จ !!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ ํจ์ฌ ๊น๋ํ๋ค์ฌ ๊ฐ์ฌํฉ๋๋ค. ๊ทธ์ ๋ ๋ ๋ฒจ์ ์ ํ์ จ๊ตฐ์ ๐
Comment on lines
+58
to
+67
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํจ์๋ก ๋บ ๊ฑฐ ์ข๋ค์!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ค์ฐ... ๊ทธ๋ ๊ตฐ์,.... ๋ฐ๋ก ๋ค์๋ฒ๋ถํฐ ๋ฐ์ํด๋จน๊ฒ ์ต๋๋ค. ๊ฐ์ฌํด์ ๐ |
||
| } | ||
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.
์ด๊ฑธ ๋ฐ๋ก ๋นผ๋์ จ๊ตฐ์!