Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.04.15 - [PG] 음양 더하기 - 월간 코딩 챌린지 시즌 2 #53

Closed
suhyunsim opened this issue Apr 16, 2021 · 0 comments
Closed
Assignees
Labels
lv.1 프로그래머스 - level 1 브루트포스 완전탐색 성공 맞은 문제

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 정답을 0으로 설정한 후 absolutes 배열에 있는 모든 수들을 차례대로 보는데, 그 수에 해당하는 signs값이 참이면 정답에 더하고, 거짓이면 정답에 빼면 됨
  • n을 두 배열의 길이라고 할 때, 시간 복잡도: O(n)

어려운 점, 실수

풀이

class Solution {
    public int solution(int[] absolutes, boolean[] signs) {
        int answer = 0;
        for (int i = 0; i < absolutes.length; i++) {
            if (!signs[i]) {
                absolutes[i] *= -1;
            }
            answer += absolutes[i];
        }
        return answer;
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 브루트포스 완전탐색 lv.1 프로그래머스 - level 1 labels Apr 16, 2021
@suhyunsim suhyunsim added this to the 4월 3주 차 milestone Apr 16, 2021
@suhyunsim suhyunsim self-assigned this Apr 16, 2021
@suhyunsim suhyunsim changed the title 21.04.15 - [PG] 음양 더하기 21.04.15 - [PG] 음양 더하기 - 월간 코딩 챌린지 시즌 2 Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lv.1 프로그래머스 - level 1 브루트포스 완전탐색 성공 맞은 문제
Projects
None yet
Development

No branches or pull requests

1 participant