-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71ba4bf
commit 31c44f4
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -41,4 +41,4 @@ for i in 1...n{ | |
} | ||
} | ||
|
||
print(result) | ||
print(result) |
This file contains 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
This file contains 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,29 @@ | ||
import Foundation | ||
|
||
func solution(_ priorities:[Int], _ location:Int) -> Int { | ||
var result = 0 | ||
var priorities = priorities | ||
var location = location | ||
|
||
while priorities.count != 0 { | ||
location -= 1 | ||
let p_max = priorities.max()! | ||
let temp = priorities[0] | ||
if p_max != temp { // max가 아닐 경우(빼야할 경우가 아닌 경우) | ||
priorities.append(temp) // 뒤에 넣기 | ||
priorities.removeFirst() // 처음꺼 빼기 | ||
if location < 0 { // location이 음수면 제일 뒤에서 부터 | ||
location = priorities.count - 1 | ||
} | ||
} else { // max일 경우(빼야할 경우) | ||
priorities.removeFirst() | ||
result += 1 | ||
if location < 0 { // location이 적절하게 오면 멈추기 | ||
break | ||
} | ||
} | ||
|
||
} | ||
|
||
return result | ||
} |