๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm/Programmers

[Programmers] ์Œ์–‘ ๋”ํ•˜๊ธฐ

 

 

๋ฌธ์ œ 

 

์–ด๋–ค ์ •์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ •์ˆ˜๋“ค์˜ ์ ˆ๋Œ“๊ฐ’์„ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด absolutes์™€ ์ด ์ •์ˆ˜๋“ค์˜ ๋ถ€ํ˜ธ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ๋ถˆ๋ฆฌ์–ธ ๋ฐฐ์—ด signs๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์‹ค์ œ ์ •์ˆ˜๋“ค์˜ ํ•ฉ์„ ๊ตฌํ•˜์—ฌ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

 

์ œํ•œ ์‚ฌํ•ญ

 

  • absolutes์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
    • absolutes์˜ ๋ชจ๋“  ์ˆ˜๋Š” ๊ฐ๊ฐ 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • signs์˜ ๊ธธ์ด๋Š” absolutes์˜ ๊ธธ์ด์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
    • signs[i] ๊ฐ€ ์ฐธ์ด๋ฉด absolutes[i] ์˜ ์‹ค์ œ ์ •์ˆ˜๊ฐ€ ์–‘์ˆ˜์ž„์„, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์Œ์ˆ˜์ž„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

 

 

๋‚˜์˜ ์ฝ”๋“œ 
def solution(absolutes, signs):
    t = 0
    for i in range(len(signs)):
        if signs[i] == True:
            t += absolutes[i]
        else:
            t += (absolutes[i] * -1)
    return t
๋ถ„์„ > ๋ถˆ๋ฆฌ์–ธ ๊ฐ’์€ ํฐ ๋”ฐ์˜ดํ‘œ ์•ˆ์— ๋„ฃ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค. ๊ผญ ๋ช…์‹ฌํ•˜์ž.