프로그래머스 2레벨 42839 소수찾기 JAVA

문제

링크 : https://programmers.co.kr/learn/courses/30/lessons/42839

한자리 숫자가 적힌 종이 조각이 흩어져있습니다. 흩어진 종이 조각을 붙여 소수를 몇 개 만들 수 있는지 알아내려 합니다.

각 종이 조각에 적힌 숫자가 적힌 문자열 numbers가 주어졌을 때, 종이 조각으로 만들 수 있는 소수가 몇 개인지 return 하도록 solution 함수를 완성해주세요.

풀이

단지 H-index의 개념이 잘 이해가 안돼서 조금 막힌 문제

거꾸로 정렬해서 가장 큰 논문이 인용된 수부터

현재 논문의 인용된 수보다 전체 몇 개 인용 됐는가 비교해서

전체 인용된 논문 수보다 큰 각 논문의 인용된 수가 몇개인지 찾는 문제

뭔가 국어문제같지만.. 문제에서 친절히 걸어준 링크를 참조하자

https://en.wikipedia.org/wiki/H-index

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Stack;


class Solution {
public int[] solution(int[] prices) {
int[] answer = new int[prices.length];
Stack<Integer> stack = new Stack<Integer>();

for(int i=0;i<prices.length;i++)

{
while( !(stack.empty()) && prices[stack.peek()] > prices[i])
{
int tmp = stack.pop();
answer[tmp] = i - tmp;
}
stack.push(i);

}

while(!stack.empty())
{
int tmp = stack.pop();
answer[tmp] = prices.length - 1 - tmp;
}

return answer;
}


}

메모

스스로 풀었는가 : ❎

국어 어질어질해서 못품…문제 이해력 부족!🙃

프로그래머스 2레벨 42839 소수찾기 JAVA

https://praisebak.github.io/2021/07/15/2021-07/p42839/

Author

Praisebak

Posted on

2021-07-15

Updated on

2021-07-15

Licensed under

Comments