We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
π¬Β λ¬Έμ
https://app.codility.com/programmers/lessons/5-prefix_sums/min_avg_two_slice/
π¬Β Idea
O(N**2)μ νμ΄λ°μ λ μ€λ₯΄μ§ μμμ νΉμλ..? νκ³ μ μΆν΄λ΄€μ§λ§ μμλ ππ!!!! O(N)μ νμ΄μ¬μΌ ν¨μ¨μ± ν μ€νΈλ₯Ό ν΅κ³Όν μ μμλ€. λ°λΌμ O(N)μ νμ΄λ₯Ό λμΆνλ € ν΄λ΄€μ§λ§ λμ ν O(N)μ μκ°λ³΅μ‘λλ₯Ό κ°λ νμ΄κ° μκ°λμ§ μμλ€. κ·Έλμ λ€λ₯Έ λΈλ‘κ·Έλ₯Ό μ°Έκ³ νλλ°, νκ· κ°μ μ리λΌλ μν 곡μμ μλ‘ μκ²λμλ€ !!
νκ· μ μ΄λ λ μκ° μμ λ κ°μ₯ μμ μλ³΄λ€ ν° κ°μ κ°μ§λ€. μ΄ μλ¦¬λ‘ μκ°ν΄λ³΄μμ λ, μμκ° 4κ°μΈ κ·Έλ£Ήμ νκ· μ μ 2κ°, λ€ 2κ°λ‘ λλμ΄λ³Έλ€λ©΄ μ λ€ μ€ μμ κ·Έλ£Ήλ³΄λ€ ν° κ°μ κ°μ§ κ²μ΄λ€. λ°λΌμ 2κ°μΈ κ·Έλ£Ήλ€μ κ³ λ €νλ©΄ 4κ°μΈ κ·Έλ£Ήμ νμΈν νμκ° μμ΄μ§λ€.
λ°λΌμ μ΄ λ¬Έμ λ₯Ό νκΈ° μν΄μ λ°°μ΄μ 2κ°, 3κ°λ‘λ§ μ¬λΌμ΄μ±ν΄μ νκ· μ ꡬν΄λ³΄λ©΄ κ°μ₯ μμ νκ· κ°μ μ μ μκ³ , μ΅μ μμ μΈλ±μ€ λν λμΆν μ μλ€.
π¬Β νμ΄
public func solution4(A : inout [Int]) -> Int { var minAvgValue: Double = Double(A[0] + A[1]) / 2 var minIndex = 0 for i in 2..<A.count { let avg2: Double = Double(A[i - 1] + A[i]) / 2 if minAvgValue > avg2 { minAvgValue = avg2 minIndex = i - 1 } let avg3: Double = Double(A[i - 2] + A[i - 1] + A[i]) / 3 if minAvgValue > avg3 { minAvgValue = avg3 minIndex = i - 2 } } return minIndex }
μκ° λ³΅μ‘λ : O(N)
μκ° λ³΅μ‘λ
νκ°ν : https://app.codility.com/demo/results/training6Y3P9V-3AR/
μ½λ리ν°β¦ μ°Έ μ’λ€ πΒ
<μ°Έκ³ >
https://nukeguys.tistory.com/175
The text was updated successfully, but these errors were encountered:
#141 - MinAvgTwoSlice λ¬Έμ νμ΄
9cb5d9e
hwangJi-dev
No branches or pull requests
π¬Β λ¬Έμ
https://app.codility.com/programmers/lessons/5-prefix_sums/min_avg_two_slice/
π¬Β Idea
O(N**2)μ νμ΄λ°μ λ μ€λ₯΄μ§ μμμ νΉμλ..? νκ³ μ μΆν΄λ΄€μ§λ§ μμλ ππ!!!! O(N)μ νμ΄μ¬μΌ ν¨μ¨μ± ν μ€νΈλ₯Ό ν΅κ³Όν μ μμλ€. λ°λΌμ O(N)μ νμ΄λ₯Ό λμΆνλ € ν΄λ΄€μ§λ§ λμ ν O(N)μ μκ°λ³΅μ‘λλ₯Ό κ°λ νμ΄κ° μκ°λμ§ μμλ€. κ·Έλμ λ€λ₯Έ λΈλ‘κ·Έλ₯Ό μ°Έκ³ νλλ°, νκ· κ°μ μ리λΌλ μν 곡μμ μλ‘ μκ²λμλ€ !!
νκ· κ°μ μ리
π‘ ꡬκ°μ νκ· μ λΆλΆκ΅¬κ°μ νκ· μ€ κ°μ₯ μμ λΆλΆκ΅¬κ°μ νκ· λ³΄λ€ ν¬λ€.νκ· μ μ΄λ λ μκ° μμ λ κ°μ₯ μμ μλ³΄λ€ ν° κ°μ κ°μ§λ€. μ΄ μλ¦¬λ‘ μκ°ν΄λ³΄μμ λ, μμκ° 4κ°μΈ κ·Έλ£Ήμ νκ· μ μ 2κ°, λ€ 2κ°λ‘ λλμ΄λ³Έλ€λ©΄ μ λ€ μ€ μμ κ·Έλ£Ήλ³΄λ€ ν° κ°μ κ°μ§ κ²μ΄λ€. λ°λΌμ 2κ°μΈ κ·Έλ£Ήλ€μ κ³ λ €νλ©΄ 4κ°μΈ κ·Έλ£Ήμ νμΈν νμκ° μμ΄μ§λ€.
λ°λΌμ μ΄ λ¬Έμ λ₯Ό νκΈ° μν΄μ λ°°μ΄μ 2κ°, 3κ°λ‘λ§ μ¬λΌμ΄μ±ν΄μ νκ· μ ꡬν΄λ³΄λ©΄ κ°μ₯ μμ νκ· κ°μ μ μ μκ³ , μ΅μ μμ μΈλ±μ€ λν λμΆν μ μλ€.
π¬Β νμ΄
μκ° λ³΅μ‘λ
: O(N)νκ°ν : https://app.codility.com/demo/results/training6Y3P9V-3AR/
μ½λ리ν°β¦ μ°Έ μ’λ€ πΒ
<μ°Έκ³ >
https://nukeguys.tistory.com/175
The text was updated successfully, but these errors were encountered: