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.07.02 - [PG] 주식 가격 #107

Closed
suhyunsim opened this issue Jul 3, 2021 · 0 comments
Closed

21.07.02 - [PG] 주식 가격 #107

suhyunsim opened this issue Jul 3, 2021 · 0 comments
Assignees
Labels
lv.2 프로그래머스 - level 2 성공 맞은 문제 스택 stack Queue

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 스택/큐 문제로 분류되어 있는데 배열로 간단히 풀이할 수 있다.

어려운 점, 실수

풀이

package main.java.com.poogle.PG.Q42584;

import java.util.Arrays;

public class Solution {
    public static int[] solution(int[] prices) {
        int[] answer = new int[prices.length];
        for (int i = 0; i < answer.length; i++) {
            for (int j = i + 1; j < answer.length; j++) {
                if (prices[i] > prices[j]) {
                    answer[i] = j - i;
                    break;
                }
                if (j == answer.length - 1) answer[i] = j - i;
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(solution(new int[]{1, 2, 3, 2, 3})));
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 lv.2 프로그래머스 - level 2 스택 stack Queue labels Jul 3, 2021
@suhyunsim suhyunsim added this to the 7월 1주 차 milestone Jul 3, 2021
@suhyunsim suhyunsim self-assigned this Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lv.2 프로그래머스 - level 2 성공 맞은 문제 스택 stack Queue
Projects
None yet
Development

No branches or pull requests

1 participant