Notice
Recent Posts
Link
- Today
- Total
hye-log
[프로그래머스]음양 더하기(Python) 본문
0. 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/76501
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 문제 설명
1) 음수 구하기
2) 합 구하기
2. 입출력
# input
absolutes = [4, 7, 12]
signs = [True, False, True]
# output
answer = 9
3. 코드
1) 첫 번째 코드
def solution(absolutes, signs):
# absolutes : 숫자 배열
# signs : 숫자의 부호
answer = 123456789
# 음수 구하기
for i in range(len(absolutes)):
if signs[i] == False:
absolutes[i] *= -1
# 합 구하기
answer = sum(absolutes)
return answer
실행 결과
4. 알게된 점
5. Github
https://github.com/iihye/Algorithm/blob/main/Programmers/neg_pos.py
GitHub - iihye/Algorithm
Contribute to iihye/Algorithm development by creating an account on GitHub.
github.com
728x90
'CodingTest > Programmers' 카테고리의 다른 글
[프로그래머스]소수 만들기(Python) (0) | 2022.08.09 |
---|---|
[프로그래머스]내적(Python) (0) | 2022.07.21 |
[프로그래머스]없는 숫자 더하기(Python) (0) | 2022.07.19 |
[프로그래머스]키패드 누르기(Python) (0) | 2022.07.18 |
[프로그래머스]숫자 문자열과 영단어(Python) (0) | 2022.07.12 |
Comments