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.
๐ ๋ฌธ์ ๋งํฌ
๋ฐฉ ๋ฒํธ
โ๏ธ ์์๋ ์๊ฐ
15๋ถ
โจ ์๋ ์ฝ๋
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
1. Swift์์ key๊ฐ์ด ์๋๊ฑธ ํ์ธํ๋ ค๋ฉด
result[key] == nil
์ ์ด์ฉํ์ฌ ๊ฐ์ด ์๋์ง ํ์ธํ๋ nil์ ์ฌ์ฉํด์ ํ์ธํ๋ค.2. Swift Intํ ๋ฐ์ฌ๋ฆผ
1๋ฒ ๋ฐฉ๋ฒ๊ณผ 2๋ฒ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
1๋ฒ ๋ฐฉ๋ฒ์ round ํจ์๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ธ๋ฐ ๋์ ์ฒ์ ๋ถ๋ถ์
import Foundation
๋ฅผ ๋ถ์ฌ์ค์ผ ํฉ๋๋ค.2๋ฒ ๋ฐฉ๋ฒ์ +1์ ํ๊ณ /2๋ฅผ ํ์ฌ์ Float์ผ๋ก ๋ฐ๊พธ์ง ์๊ณ ๋ฐ์ฌ๋ฆผ ํ๋ ๋ฐฉ์์ ๋๋ค.
2๋ฒ์ ์์์ผ๋ก๋ง ํด๊ฒฐํด์ 8ms๊ฐ ๋์จ๋ฏ!
3. ์ถ๋ ฅ ๋ถ๋ถ
์ฐธ๊ณ ์ฌ์ดํธ
Optional ๊ณต์ ๋ฌธ์
์ถ๋ ฅ์์๋
print(result.values.max())
๋ฅผ ํ๊ฒ ๋๋ฉดOptional(1)
์ด ๋์ค๊ฒ ๋์ ํ๋ฆฌ๊ฒ ๋ฉ๋๋ค.๊ทธ๋์
result.values.max()!
nil๊ฐ์ด ๋ค์ด์ฌ ์ ์๋ค๊ณ ์ ์ธํด์ฃผ๊ธฐ
result.values.max() ?? 0
nil์ด ๋ค์ด์ค๋ฉด 0์ผ๋ก ๋ฐ๊พธ๊ธฐ
์ด๋ ๊ฒ ์ฒ๋ฆฌ๋ฅผ ํด์ค ์ ์์ต๋๋ค.