๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”ฅ PS(Problem Solving) ๐Ÿ”ฅ/Codility

[Codility] Lesson 3 Time Complexity : TapeEquilibrium

by dar0m! 2021. 4. 6.

๋ฌธ์ œ

 

TapeEquilibrium coding task - Learn to Code - Codility

Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|.

app.codility.com

๊ฒฐ๊ณผ

๋ˆ„์ ํ•ฉ

 

Test results - Codility

A non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1]. The difference betw

app.codility.com

  • answer ์ดˆ๊ธฐํ™”๋ฅผ ์•„์ฃผ ํฐ ๊ฐ’์œผ๋กœ ํ•ด๋†”์•ผ ํ•˜๊ณ  (Math.abs(sum[A.length])๋กœ ํ•˜๋‹ˆ๊นŒ ํ‹€๋ ธ์—ˆ๋‹ค.)
  • 1 ~ A.length -1 ๊นŒ์ง€ sum[i]๋ฅผ ํ™œ์šฉํ•ด์„œ ์ฐจ์ด๋ฅผ ๊ตฌํ•ด์•ผ ์ •๋‹ต์ด๋‹ค. A.length๊นŒ์ง€ ๊ตฌํ•˜๋ฉด ๋˜ ํ‹€๋ฆผ..;

์ธํ„ฐ๋„ท ๊ฒ€์ƒ‰ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํ’€์ด๋„ ์žˆ์Œ

 

Test results - Codility

A non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1]. The difference betw

app.codility.com

 

๋Œ“๊ธ€