[๋ฐฑ์ค€ 2805] ๋‚˜๋ฌด ์ž๋ฅด๊ธฐ | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/๋ฐฑ์ค€ Sliver
๋ฌธ์ œ๋‚˜๋ฌด ์ž๋ฅด๊ธฐ์ •๋‹ตimport java.util.*;class Main { static int n; // ๋‚˜๋ฌด์˜ ์ˆ˜ static int m; // ๊ฐ€์ ธ ๊ฐ€๋ ค๋Š” ๊ธธ์ด static int[] arr; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); arr = new int[n]; for (int i = 0; i mid) sum += arr[i] - mid; } if(sum >= m) { answer = mid; left = mid + 1; } else { ..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv0] ์ง„๋ฃŒ์ˆœ์„œ ์ •ํ•˜๊ธฐ | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/Programmers Lv0
๋ฌธ์ œ์ง„๋ฃŒ์ˆœ์„œ ์ •ํ•˜๊ธฐํ’€์ด1import java.util.*;class Solution { public int[] solution(int[] emergency) { int[] answer = new int[emergency.length]; int[] copied = emergency.clone(); Arrays.sort(copied); for(int i = 0; i ํ’€์ด2์ฒ˜์Œ์— ํ‘ผ ์ด์ค‘ for๋ฌธ๋ณด๋‹ค HashMap์œผ๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š”๊ฒŒ ๋” ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค. ์ด์ค‘ for๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ ์ตœ๋Œ€ O(N^2)๊ฐ€ ๋˜๋Š”๋ฐ, HashMap์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ O(NlogN) ๋˜๋Š” O(N)๊นŒ์ง€ ๊ฐœ์„ ์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.import java.util.*;class S..
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv0] n ๋ฒˆ์งธ ์›์†Œ๋ถ€ํ„ฐ | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/Programmers Lv0
๋ฌธ์ œn ๋ฒˆ์งธ ์›์†Œ๋ถ€ํ„ฐ๋‚ด ํ’€์ดimport java.util.*;class Solution { public int[] solution(int[] num_list, int n) { num_list = Arrays.copyOfRange(num_list, n - 1, num_list.length); return num_list; }}copyOfRange ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐฐ์—ด์„ ๋ณต์‚ฌํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv0] ๋ฐฐ์—ด ์กฐ๊ฐํ•˜๊ธฐ | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/Programmers Lv0
๋ฌธ์ œ๋ฐฐ์—ด ์กฐ๊ฐํ•˜๊ธฐ๋‚ด ํ’€์ดimport java.util.*;class Solution { public int[] solution(int[] arr, int[] query) { for(int i = 0; i Arrays์˜ ๋ฉ”์„œ๋“œ์ธ copyOfRange๋ฅผ ์ด์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.