Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์Œ์–‘ ๋”ํ•˜๊ธฐ (level.1)

๊ฐ์ž ๐Ÿฅ” 2021. 9. 2. 16:50
๋ฐ˜์‘ํ˜•

 

๋ฌธ์ œ๋งํฌ

 

๋‚˜์˜ ํ’€์ด

  1. absolutes์™€ signs๊ฐ€ ์„œ๋กœ ๊ฐ™์€์œ„์น˜์— ๊ฐ™์€ ๋ถ€ํ˜ธ๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ๊ธฐ์— ๊ทธ๋ƒฅ ์ธ๋ฑ์Šค๋กœ ๋น„๊ต
def solution(absolutes, signs):
    total = 0
    for i in range(0, len(absolutes)):
        if signs[i] == True:
            total += absolutes[i]*(1)
        else:
            total += absolutes[i]*(-1)
    return total

 

๋‹ค๋ฅธ์‚ฌ๋žŒํ’€์ด

def solution(absolutes, signs):
    return sum(absolutes if sign else -absolutes for absolutes, sign in zip(absolutes, signs))

์ฝ”๋“œ๋ฅผ ์งง๊ฒŒ์งœ๋ ค๊ณ  ๋” ๋…ธ๋ ฅํ•ด๋ณด๊ณ  ๋” ๊ณ ๋ฏผํ•ด๋ดค์ง€๋งŒ ํฌ๊ธฐํ–ˆ๋‹ค. ํ•˜์ง€๋งŒ... ์–ด๋ฉ”์ด์ง•ํ•œ ์ฝ”๋“œ๋ฅผ ์—ญ์‹œ ใ… ใ… ใ…  
๋” ํšจ์œจ์ ์ธ ์ฝ”๋“œ๋ฅผ ์งœ๋ ค๊ณ  ๋…ธ๋ ฅํ•˜๊ณ , ์—ฐ์Šตํ•ด์•ผ๊ฒ ๋‹ค.

๋ฐ˜์‘ํ˜•