Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bishoe01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
| 1์ฐจ์‹œ | 2025.03.27 | ๊ตฌํ˜„ | [[3์ฐจ] ํŒŒ์ผ๋ช… ์ •๋ ฌ](https://school.programmers.co.kr/learn/courses/30/lessons/17686)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/1|
| 2์ฐจ์‹œ | 2025.04.09 | DP | [1277. Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones/description/?envType=problem-list-v2&envId=dynamic-programming)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/11|
| 3์ฐจ์‹œ | 2025.04.30 | DP | [1267. Count Servers that Communicate](https://leetcode.com/problems/count-servers-that-communicate/description/?envType=daily-question&envId=2025-04-29)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/16|
| 4์ฐจ์‹œ | 2025.05.09 | ๋ฌธ์ž์—ด | [1839. Longest Substring Of All Vowels in Order](https://leetcode.com/problems/longest-substring-of-all-vowels-in-order/description/)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/19|
---
68 changes: 68 additions & 0 deletions bishoe01/๋ฌธ์ž์—ด/1839.swift
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 +8 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑธ ๋”ฐ๋กœ ๋นผ๋‘์…จ๊ตฐ์š”!

Comment on lines +7 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ guard๋ฌธ ๋˜๊ฒŒ ์ข‹์€๋ฐ์š”!
๊ทธ๋Ÿฐ๋ฐ ์•„๋ž˜ ํ•€์ด ์ง  ๋กœ์ง์ƒ a๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฌด์‹œํ•˜๋Š” ๋ถ€๋ถ„์œผ๋กœ ์ปค๋ฒ„๊ฐ€ ๋˜์ง€ ์•Š์œผ๋ ค๋‚˜์š”?
(์ œ๊ฐ€ ์ž˜๋ชป ์ดํ•ดํ•œ๊ฑธ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค!_)
ํ˜น์€ ๊ฐ€๋…์„ฑ์ด๋‚˜ ์„  ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์ž‘์„ฑํ•œ ๋ถ€๋ถ„์ผ๊นŒ์š”??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ชจ์•ผ ๊ธธ ์™„์ „ ๊น”๋”ํ•˜๋‹ค

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sep037
ํ‘ธ๋Š”๋ฐ n์ผ ๊ฑธ๋ฆผ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งž์•„์š” .. !
@giljihun a๋กœ์‹œ์ž‘ํ•˜์ง€์•Š์œผ๋ฉด ๋ฌด์‹œ๋ฅผ ํ• ๊ฑด๋ฐ, ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์คฌ์Šต๋‹ˆ๋‹ค. ๋””๋ฒ„๊น…์ด๋ž‘ ๊ฐ€๋…์„ฑ ๊ฐ€์ ธ๊ฐ€๋ ค๊ณ  ํ•ด์คฌ์—ˆ์Šต๋‹ˆ๋‹ค !

var previous: Character = "z"
var count = 0
var answer = 0
Comment on lines +11 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil๋กœ ์•ˆํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil๋กœ ์‚ฌ์‹ค ํ•ด์ค˜์•ผํ•˜๋Š”๋ฐ, ์˜ต์…”๋„ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š”๊ฒŒ ์—ฌ์ „ํžˆ ์ข€ ์–ด์ƒ‰ํ•ด์„œ ํŽธํ•œ๋Œ€๋กœ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ์šฐํšŒํ•ด์„œ ํ–ˆ์Šต๋‹ˆ๋‹ค ใ…  ์•„์ง ์ต์ˆ™ํ•˜์ง€ ์•Š์•„์„œ ์ฝ”๋“œ๊ฐ€ ๊ธธ์–ด์งˆ์ˆ˜๋ก ์ต์ˆ™ํ•œ ๋ฐฉ์‹์„ ์ฑ„ํƒํ•˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”. ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” swiftyํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ข€ ์ ๊ทน ํ™œ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ท.

Comment on lines +11 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil ์ฒดํฌ๋กœ z๋ฅผ ํ•˜์‹ ๊ฑฐ๊ตฐ์š”. ์ €๋„ ํ‚จ๋”๊ตฐ๊ณผ ์งˆ๋ฌธ์ด ๋˜‘๊ฐ™์Šต๋‹ˆ๋‹ค. nil๋กœ ์•ˆํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š” ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bishoe01 ์ €๋„ ๊ถ๊ธˆํ•ด์š” ํ•€ ใ…‹ใ…‹ใ…‹ z๋กœ ํ•˜์‹  ์ด์œ ๋Š”?!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

222222 .!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์œ„์— ์ ์—‡๋“ฏ์ด nil๋กœ ์‚ฌ์‹ค ํ•ด์ค˜์•ผํ•˜๋Š”๋ฐ, ์˜ต์…”๋„ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š”๊ฒŒ ์—ฌ์ „ํžˆ ์ข€ ์–ด์ƒ‰ํ•ด์„œ ํŽธํ•œ๋Œ€๋กœ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ์šฐํšŒํ•ด์„œ ํ–ˆ์Šต๋‹ˆ๋‹ค ใ… 
์˜ต์…”๋„์ด ์•„์ง ์ต์ˆ™ํ•˜์ง€ ์•Š์•„์„œ ์ €๋Š” ์ด๋ ‡๊ฒŒ ๋ช…์‹œ์ ์œผ๋กœ ์ œ๊ฐ€ ๋””๋ฒ„๊น…ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ ์ข‹๋”๋ผ๊ตฌ์š”..! ๊ทผ๋ฐ ์˜ณ์€ ๋ฐฉ์‹์ด ์•„๋‹˜์„ ๋„ˆ๋ฌด ์ธ์ง€ํ•˜๊ณ  ์žˆ์–ด์„œ.. ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” swiftyํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ข€ ์ ๊ทน ํ™œ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ท.

// ์ถ”์›”์•ˆ๋˜๋ฉด ๋ฌด์กฐ๊ฑด ์‹œ์ž‘์€ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ค ๊ฐˆ ์ˆ˜ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ํ•จ์ˆ˜ํ™”๋ฅผ ํ•˜์…จ๊ตฐ์š”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งž์•„์š” ์•ฝ๊ฐ„ isRange dfs/bfs์—์„œ ํ•˜๋“ฏ์ด ํ™œ์šฉํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊น”๋”ํ•˜๋„ค์š”! ๋ฌธ์ž์—ด ๊นจ์กŒ์„ ๋•Œ๋ž‘ ๋ฃจํ”„ ์ข…๋ฃŒํ›„์—๋งŒ ๋ฌธ์ž์—ด ๊ธธ์ด ๋น„๊ตํ•ด์ฃผ๋ฉด ๋๋„ค์š”. ์ „ ์ดˆ์ดˆ์ดˆํ•˜๋“œ์ฝ”๋”ฉ์œผ๋กœ U๋‚˜์˜ฌ๋•Œ๋งˆ๋‹ค ๋น„๊ตํ•ด์ฃผ๋Š” ๋น„ํšจ์œจ์ ์ธ ์ฝ”๋“œ ์งฐ๋‹ต๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

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์œผ๋กœ ์˜ต์…”๋„ ๋ฐ”์ธ๋”ฉํ•ด์ฃผ๋ฉด ์–ด๋–จ๊นŒํ•ด์„œ ๋‚จ๊ฒจ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ๋ฏธ๊ฐ“ guard let ๋งˆ์Šคํ„ฐ ํ•˜์…จ๊ตฐ๋‡จ !!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ ํ›จ์”ฌ ๊น”๋”ํ•˜๋„ค์—ฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ์ƒˆ ๋˜ ๋ ˆ๋ฒจ์—…์„ ํ•˜์…จ๊ตฐ์š” ๐Ÿ‘

Comment on lines +58 to +67
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ•จ์ˆ˜๋กœ ๋บ€ ๊ฑฐ ์ข‹๋„ค์š”!
+ ๋˜ ๋‹ค์‹œ ๋Œ์•„์˜จ ์ปจ๋ฒค์…˜ ๋‹ด๋‹น..... ํ•˜์ž๋ฉด ์ €๋„ Idx๋ผ๊ณ  ๋งŽ์ด ์นญํ–ˆ๋Š”๋ฐ Swift์—์„œ๋Š” ํ’€ ๋„ค ์ž„์œผ๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ๊ด€ ๋ก€ ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ดํ›„๋กœ ์ €๋„ Index๋ผ๊ณ  ๋ช…๋ช…ํ•˜๊ณ  ์žˆ๋‹ต๋‹ˆ๋‹ค.

Copy link
Collaborator Author

@bishoe01 bishoe01 May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ค์šฐ... ๊ทธ๋ ‡๊ตฐ์š”,.... ๋ฐ”๋กœ ๋‹ค์Œ๋ฒˆ๋ถ€ํ„ฐ ๋ฐ˜์˜ํ•ด๋จน๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ด์š” ๐Ÿ‘

}