[Swift] ํ๋ก๊ทธ๋๋จธ์ค LV.0 ๋จธ์ฑ์ด๋ณด๋ค ํค ํฐ ์ฌ๋
ํ๋ก๊ทธ๋๋จธ์ค LV.0 ๋ชจ์ ๋จธ์ฑ์ด๋ณด๋ค ํค ํฐ ์ฌ๋ ๋ฌธ์ ์ค๋ช
๋จธ์ฑ์ด๋ ํ๊ต์์ ํค ์์ผ๋ก ์ค์ ์ค ๋ ๋ช ๋ฒ์งธ๋ก ์์ผ ํ๋์ง ๊ถ๊ธํด์ก์ต๋๋ค. ๋จธ์ฑ์ด๋ค ๋ฐ ์น๊ตฌ๋ค์ ํค๊ฐ ๋ด๊ธด ์ ์ ๋ฐฐ์ด array์ ๋จธ์ฑ์ด์ ํค height๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ๋จธ์ฑ์ด๋ณด๋ค ํค ํฐ ์ฌ๋ ์๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด๋ณด์ธ์. ์ ํ ์ฌํญ 1 ≤ array์ ๊ธธ์ด ≤ 100 1 ≤ height ≤ 200 1 ≤ array์ ์์ ≤ 200 ์
์ถ๋ ฅ ์ array height resutl [149, 180, 192, 170] 167 3 [180, 120, 140] 190 0 ์
์ถ๋ ฅ ์ ์ค๋ช
์
์ถ๋ ฅ ์ #1 149, 180, 192, 170 ์ค ๋จธ์ฑ์ด๋ณด๋ค ํค๊ฐ ํฐ ์ฌ๋์ 180, 192, 170์ผ๋ก ์ธ ๋ช
์
..
2022. 11. 29.
[Swift] ํ๋ก๊ทธ๋๋จธ์ค LV.0 ์ค๋ณต๋ ์ซ์ ๊ฐ์
ํ๋ก๊ทธ๋๋จธ์ค LV.0 ๋ชจ์ ์ค๋ณต๋ ์ซ์ ๊ฐ์ ๋ฌธ์ ์ค๋ช
์ ์๊ฐ ๋ด๊ธด ๋ฐฐ์ด array์ ์ ์ n์ด ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, array์ n์ด ๋ช ๊ฐ ์๋ ์ง๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด๋ณด์ธ์. ์ ํ ์ฌํญ 1 ≤ array์ ๊ธธ์ด ≤ 100 0 ≤ array์ ์์ ≤ 1,000 0 ≤ n ≤ 1,000 ์
์ถ๋ ฅ ์ array n result [1, 1, 2, 3, 4, 5] 1 2 [0. 2, 3, 4] 1 0 ์
์ถ๋ ฅ ์ ์ค๋ช
์
์ถ๋ ฅ ์ #1 [1, 1, 2, 3, 4, 5] ์๋ 1์ด 2๊ฐ ์์ต๋๋ค. ์
์ถ๋ ฅ ์ #2 [0, 2, 3, 4] ์๋ 1์ด 0๊ฐ ์์ต๋๋ค. ์ ์ถ import Foundation func solution(_ array:[Int], _ n:Int) -> Int {..
2022. 11. 29.
[Swift] Codility Lesson 5 - CountDiv
๋ฌธ์ Write a function: public func solution(_ A : Int, _ B : Int, _ K : Int) -> Int that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.: { i : A ≤ i ≤ B, i mod K = 0 } For example, for A = 6, B = 11 and K = 2, your function should return 3, because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 an..
2022. 7. 26.