-
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
Conversation
alstjr7437
left a comment
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.
์ ๋ ํ๊ณผ ๊ฐ์ด ๋ญ๊ฐ ๊น๋ํ ๋ชปํ๊ณ ์์ฒญ ์ง๊ด์ ์ผ๋ก ํ์ํ๊ฑฐ ๋ฐ๋ก๋ฐ๋ก ๊ฐ์ ธ๋ค ์ฐ๋ฉด์ ํ์์ต๋๋ค ใ ..
class Solution {
func longestBeautifulSubstring(_ word: String) -> Int {
var previous: Character?
var count = 0
var answer = 0
var currentVowelIndex = 0 // 0: 'a', 1: 'e', 2: 'i', 3: 'o', 4: 'u'
for current in word {
if current == "a" && currentVowelIndex == 0 {
count = 1
previous = "a"
currentVowelIndex = 1
} else if current == "e" && currentVowelIndex == 1 {
count += 1
previous = "e"
currentVowelIndex = 2
} else if current == "i" && currentVowelIndex == 2 {
count += 1
previous = "i"
currentVowelIndex = 3
} else if current == "o" && currentVowelIndex == 3 {
count += 1
previous = "o"
currentVowelIndex = 4
} else if current == "u" && currentVowelIndex == 4 {
count += 1
previous = "u"
answer = max(answer, count)
} else if current == previous {
count += 1
} else {
if current == "a" {
count = 1
previous = "a"
currentVowelIndex = 1
} else {
count = 0
previous = nil
currentVowelIndex = 0
}
}
}
return answer
}
}
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
์ด๊ฑธ ๋ฐ๋ก ๋นผ๋์ จ๊ตฐ์!
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
nil๋ก ์ํ์ ์ด์ ๊ฐ ์์๊น์?
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.
nil๋ก ์ฌ์ค ํด์ค์ผํ๋๋ฐ, ์ต์
๋ ์ฒ๋ฆฌํด์ฃผ๋๊ฒ ์ฌ์ ํ ์ข ์ด์ํด์ ํธํ๋๋ก ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ์ฐํํด์ ํ์ต๋๋ค ใ
์์ง ์ต์ํ์ง ์์์ ์ฝ๋๊ฐ ๊ธธ์ด์ง์๋ก ์ต์ํ ๋ฐฉ์์ ์ฑํํ๋ ๊ฒ ๊ฐ์์. ๋ค์๋ถํฐ๋ swiftyํ ์ ์๊ฒ ์ข ์ ๊ทน ํ์ฉํด๋ณด๊ฒ ์ต๋๋ท.
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
์ค ๊ฐ ์ ์๋์ง ์๋์ง ํจ์ํ๋ฅผ ํ์ จ๊ตฐ์
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.
๋ง์์ ์ฝ๊ฐ isRange dfs/bfs์์ ํ๋ฏ์ด ํ์ฉํด๋ดค์ต๋๋ค.
YooGyeongMo
left a comment
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.
๋ฉ์ง ์ฝ๋๋ค์ ํ.
nill์ ์์๋ก ์ค์ C์ธ์ด์ฒ๋ผ ๋งจ๋ค์ null ๊ฐ๋ฆฌํค๋ ๊ฒ๊ณผ ๋๊ฐ์ ์๋ฆฌ๋ค์
๋ง์ฝ์ z๊ฐ ์๋
var previous: Character? = nil
if previous == nil {
}๋ก ์คฌ๋ค๋ฉด ์ด๋จ๊น์ฉ ? ํ์ ์์ ์ฑ์ด ์ข ๋ ๋ณด์ฅ๋๋ ๋๋๊ฐ์์ ์ ์ด๋ดค์ต๋๋ท
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
nil ์ฒดํฌ๋ก z๋ฅผ ํ์ ๊ฑฐ๊ตฐ์. ์ ๋ ํจ๋๊ตฐ๊ณผ ์ง๋ฌธ์ด ๋๊ฐ์ต๋๋ค. nil๋ก ์ํ์ ์ด์ ๊ฐ ์์๊น์ ?
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.
@bishoe01 ์ ๋ ๊ถ๊ธํด์ ํ ใ ใ ใ z๋ก ํ์ ์ด์ ๋?!
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.
222222 .!
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.
์์ ์ ์๋ฏ์ด nil๋ก ์ฌ์ค ํด์ค์ผํ๋๋ฐ, ์ต์
๋ ์ฒ๋ฆฌํด์ฃผ๋๊ฒ ์ฌ์ ํ ์ข ์ด์ํด์ ํธํ๋๋ก ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ์ฐํํด์ ํ์ต๋๋ค ใ
์ต์
๋์ด ์์ง ์ต์ํ์ง ์์์ ์ ๋ ์ด๋ ๊ฒ ๋ช
์์ ์ผ๋ก ์ ๊ฐ ๋๋ฒ๊น
ํ ์ ์์ผ๋๊น ์ข๋๋ผ๊ตฌ์..! ๊ทผ๋ฐ ์ณ์ ๋ฐฉ์์ด ์๋์ ๋๋ฌด ์ธ์งํ๊ณ ์์ด์.. ๋ค์๋ถํฐ๋ swiftyํ ์ ์๊ฒ ์ข ์ ๊ทน ํ์ฉํด๋ณด๊ฒ ์ต๋๋ท.
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
์ด ๋ถ๋ถ์
guard let prevIdx = vowels.firstIndex(of: previous),
let currIdx = vowels.firstIndex(of: current) else {
return false
}
return currIdx >= prevIdx && currIdx - prevIdx <= 1๋ก ์ค๋ณต์กฐ๊ฑด ์ ๊ฑฐํ๊ณ , guard let์ผ๋ก ์ต์ ๋ ๋ฐ์ธ๋ฉํด์ฃผ๋ฉด ์ด๋จ๊นํด์ ๋จ๊ฒจ๋ณด์์ต๋๋ค.
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.
๋ฐ๋ฏธ๊ฐ guard let ๋ง์คํฐ ํ์ จ๊ตฐ๋จ !!
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.
์ ํจ์ฌ ๊น๋ํ๋ค์ฌ ๊ฐ์ฌํฉ๋๋ค. ๊ทธ์ ๋ ๋ ๋ฒจ์ ์ ํ์ จ๊ตฐ์ ๐
giljihun
left a comment
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.
์ ๋ ๋น์ทํ ์ ์๋? ์ฌ๋ผ์ด๋ฉ ์๋์ฐ ์คํ์ผ๋ก ๊ตฌํ์ ํ๋๋ฐ์.
์กฐ๊ฑด์ ๋ง์กฑํ์ง ์๋ ์์ ์, start / count๋ฅผ ๋ฆฌ์
ํ๋ฉด์
์๋์ฐ๋ฅผ ์ด๋ํ๋ฉด์ ๊ฒ์ฌํ์ด๋ค.
func longestBeautifulSubstring(_ word: String) -> Int {
let word = Array(word)
var maxLength = 0
var start = 0
var count = 0
for i in 1..<word.count {
if word[i] < word[i - 1] {
start = i
count = 0
} else if word[i] > word[i - 1] {
count += 1
}
if word[start] == "a", count == 4 {
maxLength = max(maxLength, i - start + 1)
}
}
return maxLength
}์ฃผ์ ๋ก์ง
for i in 1..<word.count {
if word[i] < word[i - 1] {
start = i
count = 0
} else if word[i] > word[i - 1] {
count += 1
}
if word[start] == "a", count == 4 {
maxLength = max(maxLength, i - start + 1)
}
}- ๋ฌธ์์ ์์คํค๊ฐ ๊ธฐ์ค์ผ๋ก ๋์๋ฅผ ๋น๊ตํ์!
- ๋ฌธ์ ์์๊ฐ ๊นจ์ง๋ค -> start๋ฅผ ์ฌ์ค์ , count ์ด๊ธฐํ
- count๊ฐ 4์ด๊ณ ์์๋ฌธ์๊ฐ a์ธ ๊ฒฝ์ฐ์๋ง ๋ทฐํฐํ๋ผ์ดํ๋ก ใ ใ ํด์ฃผ๊ณ ๊ธธ์ด๋ฅผ ๊ฐฑ์ ํด์ค.
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
์ฌ๊ธฐ guard๋ฌธ ๋๊ฒ ์ข์๋ฐ์!
๊ทธ๋ฐ๋ฐ ์๋ ํ์ด ์ง ๋ก์ง์ a๋ก ์์ํ์ง ์์ผ๋ฉด ๋ฌด์ํ๋ ๋ถ๋ถ์ผ๋ก ์ปค๋ฒ๊ฐ ๋์ง ์์ผ๋ ค๋์?
(์ ๊ฐ ์๋ชป ์ดํดํ๊ฑธ ์๋ ์์ต๋๋ค!_)
ํน์ ๊ฐ๋
์ฑ์ด๋ ์ ์์ธ์ฒ๋ฆฌ๋ฅผ ์ํด ์์ฑํ ๋ถ๋ถ์ผ๊น์??
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.
๋ชจ์ผ ๊ธธ ์์ ๊น๋ํ๋ค
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.
@sep037
ํธ๋๋ฐ n์ผ ๊ฑธ๋ฆผ
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.
๋ง์์ .. !
@giljihun a๋ก์์ํ์ง์์ผ๋ฉด ๋ฌด์๋ฅผ ํ ๊ฑด๋ฐ, ๊ฐ๋
์ฑ์ ์ํด์ ์ฒ๋ฆฌ๋ฅผ ํด์คฌ์ต๋๋ค. ๋๋ฒ๊น
์ด๋ ๊ฐ๋
์ฑ ๊ฐ์ ธ๊ฐ๋ ค๊ณ ํด์คฌ์์ต๋๋ค !
MuchanKim
left a comment
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.
ํํ ๋ฌธ์ ์๋ชป์ดํดํ๊ณ ํ๋ค๊ฐ ์๊ฐ ๋๋ฌด ์จ๋ฒ๋ฆผ. ์๋ฆ๋ค์ฐ์ ๋ฌธ์๊ฐ ์กด์ฌํ๊ธฐ๋ง ํ๋ฉด ๋๋ ์ค ์์๋๋ฐ ์๋์๊ตฐ์;; ์์๋๋ก ๋์์ผํ์. ์ ์๊ฐ์ ํ๋ฆ๋๋ก ํ์์ต๋๋ค. ์ต์ ํ ํ ์ ์์๊ฑฐ ๊ฐ์๋ฐ ์๊ฐ๋๋ฉด ์ต์ ํ ํด๋ณด๊ฒ ์ต๋๋ค.^~^
๋ฌธ์ ๋ ํ์์ดํ์ผ๋ก ํ์ด๋ณด๊ณ ๋ค๋ฅธ๋ถ๋ค ์ฝ๋ ์ฝ๋๊ฒ์ ์๊ฐ ๋น์ค์ ๋๋ฆฌ๋๊น ์ฌ๋ฐ๋ค์ ใ
// ์งํ์ค์ธ ๋ถ๋ถ ๋ฌธ์์ด ๊ธธ์ด, ์๋ฆ๋ค์ด๋ฌธ์์ด ์ค ๊ฐ์ฅ ๊ธด์ ๋ฐ๋ก ๋ด์์ผ ํจ
// ๊ทธ๋ฆฌ๊ณ ๊ฐ ๋ชจ์ ์ธ๋ฑ์ค ํ์ฉํด์ค์ผ ํ ๋ฏ
// ์ฒซ a๋์ค๋ฉด ํ์ฌ ๊ธธ์ด, ์ธ๋ฑ์ค 1์ก๊ณ ์์
// ๊ฐ์ ๋ฌธ์ ๋์ค๋ฉด ๋ฌธ์์ด ๊ธธ์ด๋ง ๋๋ ค์ค.
// ๋ค์ ๋ฌธ์๋์ค๋ฉด ํ์ฌ ๊ธธ์ด ๋๋ ค์ฃผ๊ณ ๋ค์ ๋ฌธ์ select
// ๋ฐ๋ณต
// ๋ง์ง๋ง ๋ฌธ์ ๋์ค๋ฉด ์ ์ฅ ํ ์ต๋ํฌ๊ธฐ ๋ฌธ์์ด์ด๋ ๋น๊ต
// ๊ทผ๋ฐ ๋ ๋์จ๋ค? ์ ์ฅ ํ ์ต๋ํฌ๊ธฐ ๋ฌธ์์ด์ด๋ ๋น๊ต -> ์ด๋ถ๋ถ ์ต์ ํํ๊ณ ์ถ์
// ์ค๊ฐ์ ๊นจ์ง๋ฉด ์ด๊ธฐํ ํด์ฃผ๊ธฐ.
class Solution {
func longestBeautifulSubstring(_ word: String) -> Int {
var currentLength = 0
var maxLength = 0
var vowelIndex = 0
for char in word {
if char == "a" && vowelIndex == 0 {
currentLength = 1
vowelIndex = 1
}
else if char == "a" && vowelIndex == 1 {
currentLength += 1
}
else if char == "e" && vowelIndex == 1 {
currentLength += 1
vowelIndex = 2
}
else if char == "e" && vowelIndex == 2 {
currentLength += 1
}
else if char == "i" && vowelIndex == 2 {
currentLength += 1
vowelIndex = 3
}
else if char == "i" && vowelIndex == 3 {
currentLength += 1
}
else if char == "o" && vowelIndex == 3 {
currentLength += 1
vowelIndex = 4
}
else if char == "o" && vowelIndex == 4 {
currentLength += 1
}
else if char == "u" && vowelIndex == 4 {
currentLength += 1
vowelIndex = 5
maxLength = max(maxLength, currentLength)
}
else if char == "u" && vowelIndex == 5 {
currentLength += 1
maxLength = max(maxLength, currentLength)
}
else {
if char == "a" {
currentLength = 1
vowelIndex = 1
} else {
currentLength = 0
vowelIndex = 0
}
}
}
return maxLength
}
}
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
@bishoe01 ์ ๋ ๊ถ๊ธํด์ ํ ใ ใ ใ z๋ก ํ์ ์ด์ ๋?!
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
ํจ์๋ก ๋บ ๊ฑฐ ์ข๋ค์!
+ ๋ ๋ค์ ๋์์จ ์ปจ๋ฒค์
๋ด๋น..... ํ์๋ฉด ์ ๋ Idx๋ผ๊ณ ๋ง์ด ์นญํ๋๋ฐ Swift์์๋ ํ ๋ค ์์ผ๋ก ์์ฑํ๋ ๊ฒ์ด ๊ด ๋ก ๋ผ๊ณ ํฉ๋๋ค. ๊ทธ ์ดํ๋ก ์ ๋ Index๋ผ๊ณ ๋ช
๋ช
ํ๊ณ ์๋ต๋๋ค.
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.
์ค์ฐ... ๊ทธ๋ ๊ตฐ์,.... ๋ฐ๋ก ๋ค์๋ฒ๋ถํฐ ๋ฐ์ํด๋จน๊ฒ ์ต๋๋ค. ๊ฐ์ฌํด์ ๐
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
๊น๋ํ๋ค์! ๋ฌธ์์ด ๊นจ์ก์ ๋๋ ๋ฃจํ ์ข ๋ฃํ์๋ง ๋ฌธ์์ด ๊ธธ์ด ๋น๊ตํด์ฃผ๋ฉด ๋๋ค์. ์ ์ด์ด์ดํ๋์ฝ๋ฉ์ผ๋ก U๋์ฌ๋๋ง๋ค ๋น๊ตํด์ฃผ๋ ๋นํจ์จ์ ์ธ ์ฝ๋ ์งฐ๋ต๋๋ค.
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.
๊ธธ์ ์๋ ํ์ด (์ฌ๋ผ์ด๋ฉ ์๋์ฐ)๊ฐ ์ฐ ์ ์์ธ๊ฒ๊ฐ์์..! ์ ๋ ๋ง ๊ตฌํํ๋ฏ์ด ์ด๊ฒ์ ๊ฒ์ฐ๋ฌ๋ณธ๊ฑฐ๋ผ...! ์์ง ๊ฐ๊ธธ์ด๋จธ๋ค์.. ๐
|
๋ฌธ์ ํธ๋๋ฐ ๋ฃจ๋ฏธ๊ฐ ์ง๋๊ฐ๊ธธ๋ ๋ฃจ๋ฏธ์ ๋์์ ์ด ~ ์ง ๋ฐ์์ต๋๋ค ใ //
// main.swift
// Leet_1839
//
// Created by Seungeun Park on 5/16/25.
//
import Foundation
class Solution {
func longestBeautifulSubstring(_ words: String) -> Int {
let wordCount = words.count // ๋ฌธ์์ด ์ซ์ ์ธ๊ธฐ
var aeiouIndex : Int = 0 // a,e,i,o,u ์ค ๋ช ๋ฒ์งธ ์ํ๋ฒณ์ ๊ฐ๋ฆฌํค๋์ง
let wordArray = Array(words)
var charCount : Int = 1 // ์ด์ฐจํผ ํด๋น ์๊ฐ ํฌํจ๋ ๊ฑฐ๋๊น 1๋ก ๊ณ ์
var beautifulStringCount : Int = 0
for i in 1..<wordCount {
let prev = wordArray[i - 1]
let curr = wordArray[i]
if curr >= prev {
/*
a ๋ค์์ผ๋ก a, e๊ฐ ๋์ฌ ์ ์๊ณ ,
e ๋ค์์ผ๋ก e, i๊ฐ ๋์ฌ ์ ์๊ณ ,
i ๋ค์์ผ๋ก i, o๊ฐ ๋์ฌ ์ ์๊ณ ,
o ๋ค์์ผ๋ก o, u๊ฐ ๋์ฌ ์ ์๊ณ ,
u ๋ค์์ผ๋ก๋ u๋ง ๋์ฌ ์ ์์
*/
charCount += 1
if curr != prev {
aeiouIndex += 1 // ๋์ผํ ๊ธ์๊ฐ ์๋๋ฉด ๋ค์ ๋ชจ์์ผ๋ก ๋์ด๊ฐ
}
if aeiouIndex == 4 { // ์๋ฒฝํ๊ฒ ๋์ด
beautifulStringCount = max(charCount, beautifulStringCount)
}
} else {
charCount = 1
if curr == "a" {
aeiouIndex = 0
} else {
aeiouIndex = 0 // ๋๋ -1, ์ ํ ๊ฐ๋ฅ
}
}
}
return beautifulStringCount
}
} |
bishoe01/๋ฌธ์์ด/1839.swift
Outdated
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.
222222 .!
๐ ๋ฌธ์ ๋งํฌ
Leetcode1839
๋์ด๋ Medium ์ค์์ ์ ๋ต๋ฅ ๋ฑ ์ ๋ฐ์ธ๊ฑฐ๋ก ํด๋ดค์ต๋๋ค ! ์ฐจ์ธฐ์ฐจ์ธฐ ๋ด๋ ค๊ฐ๋ค๊ฐ HARD์์ ์ ๋ต๋ฅ ๋์๊ฑฐ๋ก ๋ฐ๊ฟ๊ฐ ์๊ฐ์ ๋๋ท
โ๏ธ ์์๋ ์๊ฐ
1h
โจ ์๋ ์ฝ๋
์ด์ฒํผ ๋ชจ์๋ง์ ์ทจ๊ธํ๊ณ ์์ด์
vowels๋ฐฐ์ด์ ๋ง๋ค์ด์คฌ์ต๋๋ค.canGoํจ์๋ฅผ ํตํด์vowels.firstIndexํ์ฉ - ๊ฐ index๋น๊ต๋ฅผ ํตํดa-e-i-o-u์์๋ก ๋์ค๋ ๊ฒ์ ์ง์ผ์ฃผ๋ ค๊ณ ํ์ต๋๋ค.๋ฐฐ์ด์ ์์ฐ๊ณ ํ์ด๋ณด๊ณ ์ถ์ด์, ๊ฐ์ฅ ๋ง์ง๋ง์ ์ฒดํฌํ ์ํ๋ฒณ์ ์ฒดํฌํ๊ธฐ ์ํด์
previous๋ฅผ ๋ง๋ค์์ด์. ์ด๊ธฐ๊ฐ์ด z์ธ ์ด์ ๋ nil์ ์ฐ๊ธฐ ์ซ์ด์,, ์ด์ฒํผ ๋ชจ์๋ง ๋์ค๋๊น 'z'๋ฅผ ํตํด์ ์์์ ์ ์ก์์ฃผ๋ ค๊ณ ํ์ต๋๋ค. (๋ ์ข์ ๋ฐฉ๋ฒ์ด ์๋ค๋ฉด ์๋ ค์ฃผ์ธ์..!)๋ฐ๋ณต๋ฌธ๋ก์ง
word์์ ๋ฐ๋ณต๋ฌธ์ ๋๋ฉด์z์ผ๋(์ฒ์์ด๊ฑฐ๋, ๋๋ค๊ฐ ๋๊ฒผ์๋) ์ ๋ํด์a๋ฅผ ๋ง๋ ๋๊น์ง continue์น๋ฉด์ ๋์ด๊ฐ๋๋ค !canGo๋ฅผ ํตํด์ ์ด์ ์ ๋ ๊ฐ์ ๊ฐ์ด๊ฑฐ๋, ๋ฐ๋ก ๋ค์ ๋ชจ์์ด๋ผ๋ฉดcount+1ํ๊ณprevious๋ฅผ ํ์ฌ๊ฐ์ผ๋ก ๋ฐ๊ฟ์ค๋๋ค ! (์ฌ์ค์ ๋ฐฐ์ด๋ก ๋ฐ์ง๋ฉด๋ฐฐ์ด.last๊ฐ ๋ ๊ฒ ๊ฐ๋ค์.previous == u์ด ๋ถ๋ถ์ด ์ดํด์๋์ค ์๋ ์์ ๊ฒ๊ฐ์๋ฐ (์๋ฅผ๋ค์ดaeio๊น์ง ๋์ค๊ณu์์ด ๋๊ฒจ๋ฒ๋ฆฌ๋ฉด ์นด์ดํ ์ ํด์ฃผ๋ฉด ์๋๋๊น)๋ชจ์์ด ์์๋๋ก ๋์์ผํ๋, ๋ง์ง๋ง๊ฐ์ด
u๋ค? ๊ทธ๋ฌ๋ฉด ๋ชจ์ ๋ค ๋ค์ด์๊ฒ ๋ค?๋ฅผ ์ง์ํ๊ณanswer๊ฐ์ ๊ฑด๋ค ์ ์์ต๋๋ค !u์ธ์ง๋ฅผ ํ๋จํ๊ณ , answer๊ฐ์ ํ๋ฒ ๋ ๊ฑด๋๋ ค์ค๋๋ค ! , ๊ทธ๊ฒ ์๋๋ผ๋ฉด ๊ทธ๋ฅ answer ๋!์ด ๋ถ๋ถ์ ์กฐ๊ฑด๋ฌธ ์๋ฃ๊ณ ๊ทธ๋ฅ ํญ์
return max(answer, count)ํด์ฃผ๋ฉด ๋๋๊ฑฐ ์๋์ผ? ํ์ค ์ ์๊ฒ ์ง๋ง๋ฐ๋ก
aaaaa๋ผ๋ ๋ฐ๋ก์ ๋ํด์ 0์ด ์๋ 5๋ฅผ ๋ด๋ฑ์ต๋๋ค !ํ๋ฒ์ ๊ผผ๊ผผํ๊ฒ ํ์ด์ผํ๋๋ฐ, ๊ณ์ ์ ์ถ-๋ฐ๋ก ํด๊ฒฐ-์ ์ถ-๋ฐ๋ก ํด๊ฒฐ์ ๋ฐ๋ณตํ๋ค์..! ๋ค์์๋ ํ๋ฒ์ ํด๊ฒฐ๋๋๊ฑธ ๋ชฉํ๋ก ์ข ๋ ์ ์คํ๊ฒ ์ง๋ณด๊ฒ ์ต๋๋ค.