[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv0] ์ˆจ์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๋ง์…ˆ (2) | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/Programmers Lv0
๋ฌธ์ œ์ˆจ์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๋ง์…ˆ (2)ํ’€์ดclass Solution { public int solution(String my_string) { int answer = 0; String[] strArr = my_string.replaceAll("[a-zA-Z]", " ").split(" "); for(String str : strArr) { if(!str.equals("")) answer += Integer.parseInt(str); } return answer; }}๋ชจ๋“  ์•ŒํŒŒ๋ฒณ์„ ์ œ๊ฑฐํ•ด์•ผํ•˜๋Š”๋ฐ replaceAll("[a-zA-Z]", " ")๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ์•ŒํŒŒ๋ฒณ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค Lv0] ์ž˜๋ผ์„œ ๋ฐฐ์—ด๋กœ ์ €์žฅํ•˜๊ธฐ | ์ž๋ฐ”
ยท
๐Ÿ“ Coding Test/Programmers Lv0
๋ฌธ์ œ์ž˜๋ผ์„œ ๋ฐฐ์—ด๋กœ ์ €์žฅํ•˜๊ธฐ ํ’€์ดclass Solution { public String[] solution(String my_str, int n) { int length = my_str.length() % n == 0 ? my_str.length() / n : my_str.length() / n + 1; String[] answer = new String[length]; for (int i = 0; i
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 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๋ฅผ ์ด์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.