From addf9e4e697744de60f2f8af5554c733bc295271 Mon Sep 17 00:00:00 2001 From: sujunghwang <64738942+sujunghwang@users.noreply.github.com> Date: Thu, 23 Feb 2023 09:45:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Week05=20PRG=2042584=20=EC=A3=BC=EC=8B=9D?= =?UTF-8?q?=EA=B0=80=EA=B2=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sujunghwang/week05/PRG_42584.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 sujunghwang/week05/PRG_42584.java diff --git a/sujunghwang/week05/PRG_42584.java b/sujunghwang/week05/PRG_42584.java new file mode 100644 index 0000000..6592743 --- /dev/null +++ b/sujunghwang/week05/PRG_42584.java @@ -0,0 +1,27 @@ +/* +https://school.programmers.co.kr/learn/courses/30/lessons/42584?language=java + +주어진 배열을 탐색하면서 현재 값보다 작은 값이 언제 나오는지 구하면 되는 문제 +문제 카테고리는 스택/큐 였는데 모르겠어서 그냥 배열로 이중 for loop 돌림 +효율성 문제 생길 줄 알았는데 안생겨서 그냥 넘어가기로 함 +*/ + +class Solution { + public int[] solution(int[] prices) { + int len = prices.length; + int[] answer = new int[len]; + + for(int i = 0; i < len-1; i++){ + answer[i] = 1; + for(int j = i+1; j < len-1; j++){ + if(prices[j] >= prices[i]){ + answer[i] += 1; + } else { + break; + } + } + } + + return answer; + } +} From 18d3cc28cb03629a9638df753563c4f40ad4c41e Mon Sep 17 00:00:00 2001 From: sujunghwang <64738942+sujunghwang@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:04:55 +0900 Subject: [PATCH 2/3] Week05 PRG 42747 H-Index --- sujunghwang/week05/PRG_42747.java | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sujunghwang/week05/PRG_42747.java diff --git a/sujunghwang/week05/PRG_42747.java b/sujunghwang/week05/PRG_42747.java new file mode 100644 index 0000000..6b6e411 --- /dev/null +++ b/sujunghwang/week05/PRG_42747.java @@ -0,0 +1,34 @@ +/* +https://school.programmers.co.kr/learn/courses/30/lessons/42747?language=java + +주어진 배열에서 n보다 큰 값이 n개 이상인 값 중 최대값을 찾는 문제 +주어진 배열을 역순으로 정렬해서 가장 큰 값을 max로 놓고 1씩 빼면서 배열에 있는 값들과 비교 +*/ + +import java.util.Arrays; +class Solution { + public int solution(int[] citations) { + int answer = 0; + int len = citations.length; + + Arrays.sort(citations); + int[] ord = new int[len]; + for (int i = 0; i < len; i++) { + ord[i] = citations[len-i-1]; + } + int max = ord[0]; + + for (int i = max; i >= 0; i--) { + int cnt = 0; + for (int j : ord) { + if(j >= i) cnt++; + } + if(cnt >= i) { + answer = i; + break; + } + } + + return answer; + } +} From b35fe54c75186228a63d88ddd3599e99142996e9 Mon Sep 17 00:00:00 2001 From: sujunghwang <64738942+sujunghwang@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:06:18 +0900 Subject: [PATCH 3/3] Delete PRG_42584.java --- sujunghwang/week05/PRG_42584.java | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 sujunghwang/week05/PRG_42584.java diff --git a/sujunghwang/week05/PRG_42584.java b/sujunghwang/week05/PRG_42584.java deleted file mode 100644 index 6592743..0000000 --- a/sujunghwang/week05/PRG_42584.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -https://school.programmers.co.kr/learn/courses/30/lessons/42584?language=java - -주어진 배열을 탐색하면서 현재 값보다 작은 값이 언제 나오는지 구하면 되는 문제 -문제 카테고리는 스택/큐 였는데 모르겠어서 그냥 배열로 이중 for loop 돌림 -효율성 문제 생길 줄 알았는데 안생겨서 그냥 넘어가기로 함 -*/ - -class Solution { - public int[] solution(int[] prices) { - int len = prices.length; - int[] answer = new int[len]; - - for(int i = 0; i < len-1; i++){ - answer[i] = 1; - for(int j = i+1; j < len-1; j++){ - if(prices[j] >= prices[i]){ - answer[i] += 1; - } else { - break; - } - } - } - - return answer; - } -}