-
음양 더하기코딩 테스트/Level 1 2021. 7. 19. 22:29반응형
https://programmers.co.kr/learn/courses/30/lessons/76501
파이썬
def solution(absolutes, signs): answer = 0 for each in zip(absolutes, signs): answer += each[0] * (1 if each[1] else -1) return answer
def solution(absolutes, signs): return sum(each[0] * (1 if each[1] else -1) for each in zip(absolutes, signs))
solution = lambda absolutes, signs: sum(each[0] * (1 if each[1] else -1) for each in zip(absolutes, signs))
golang
func solution(absolutes []int, signs []bool) (sum int) { for i, v := range absolutes { if signs[i] { sum += v } else { sum -= v } } return sum }
Java
class Solution { public int solution(int[] absolutes, boolean[] signs) { var answer = 0; for (var i = 0; i < absolutes.length; i++) answer += absolutes[i] * (signs[i] ? 1 : -1); return answer; } }
반응형