Deep_Dev
article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ์นด๋“œ๋ญ‰์น˜

cards1 ๊ณผ carsd2์— index๋ฅผ ๋Œ๋ฉด์„œ, ๋‘ ๋ฐฐ์—ด์—์„œ ๋ชจ๋‘ ๋งค์นญ๋˜๋Š” ๋‹จ์–ด๊ฐ€ ์—†์„์‹œ ๋ฐ”๋กœ "No"๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ๋˜๊ณ , ๋งค์นญ๋˜๋Š” ๋‹จ์–ด๊ฐ€ ์žˆ์„์‹œ ํ•ด๋‹น ๋ฐฐ์—ด์˜ index๋ฅผ ์ฆ๊ฐ€ ์‹œํ‚ค๋ฉด ๋œ๋‹ค. ์‹ ๊ทœ๋ฌธ์ œ์ธ๋ฐ, Level 1์—์„  ์‰ฌ์šดํŽธ์— ์†ํ•˜๋Š”๊ฑฐ ๊ฐ™๋‹ค. class Solution { public String solution(String[] cards1, String[] cards2, String[] goal) { String answer = "No"; int lt = 0; // cards1 index int rt = 0; // cards2 index for(int md=0; md

article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ๋ฌธ์ž์—ด ๋‚˜๋ˆ„๊ธฐ

์ฒ˜์Œ์— ๋ฌธ์ œ๋ฅผ ์ž˜๋ชป ์ฝ์–ด์„œ ์ข€ ๋Œ์•„๊ฐ”๋Š”๋ฐ.. ๊ทธ๋ƒฅ ๋“ฑ์žฅํ•œ ๋ฌธ์ž๋งˆ๋‹ค ๊ฐ™์€ ํšŸ์ˆ˜๋กœ ๋‚˜์˜จ๊ฒŒ ์žˆ๋‹ค๋ฉด ๋ฐ”๋กœ ์นด์šดํŠธ ํ•ด์ฃผ๋Š”์ค„ ์•Œ์•˜๋Š”๋ฐ, ๋ฌด์กฐ๊ฑด '์ฒซ๋ฌธ์ž์™€ ๋‚˜๋จธ์ง€ ๋ฌธ์ž์˜ ๋“ฑ์žฅ ํšŸ์ˆ˜'๋กœ ํŒ๋‹จํ•œ๋‹ค. aaabbcab -> aaabbc / ab aabcabcd -> aabc / ab / cd ๋ฌธ์ž์—ด์— ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ž๋ฅผ ์ง€์ • ํ›„ ๋‘ ๋ฒˆ์งธ ๋ฌธ์ž๋ถ€ํ„ฐ for ๋ฌธ ๊ฐ™์„ ๊ฒฝ์šฐ start++, ์•„๋‹ ๊ฒฝ์šฐ end++, ๋งŒ์•ฝ ๋‘ count๊ฐ€ ๊ฐ™๋‹ค๋ฉด break ๋‹ค ๋Œ์•„๊ฐ„ count ์ˆ˜์˜ ํ•ฉ ๋งŒํผ ๋ฌธ์ž์—ด์„ ์ž๋ฅด๊ธฐ 1-2-3 ์˜ ์ˆœ์„ ๋ฌธ์ž์—ด์ด ์—†์–ด์งˆ ๋•Œ ๊นŒ์ง€ ๋ฐ˜๋ณต class Solution { public int solution(String s) { int answer = 0; while(s.length()!=0){ answer++; char c..

article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ์†Œ์ˆ˜ ๋งŒ๋“ค๊ธฐ

๋งŽ์€ ์ˆ˜์˜ ์†Œ์ˆ˜๋ฅผ ํŒ๋ณ„ํ•ด์•ผํ–ˆ๊ธฐ์— ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด๋ฅผ ์ด์šฉํ•ด์„œ ํ’€๋ ค๊ณ ํ–ˆ๋Š”๋ฐ, ์ตœ๋Œ€ ์ˆ˜์˜ ๋ฒ”์œ„ ์„ค์ •์„ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ๋ชจ๋ฅด๊ฒ ์–ด์„œ ๊ทธ๋ƒฅ 3์ค‘ for๋ฌธ๊ณผ ์†Œ์ˆ˜ํŒ๋ณ„ ํ•จ์ˆ˜๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค. ๋‹ค ํ’€๊ณ ๋‚˜์„œ ๋” ํšจ์œจ์ ์ธ ์ฝ”๋“œ๋ฅผ ๋ณด๋ ค๊ณ  ๋‹ค๋ฅธ์‚ฌ๋žŒ๋“ค์˜ ํ’€์ด๋ฅผ ๋ดค๋Š”๋ฐ 3์ค‘ ํฌ๋ฌธ์œผ๋กœ ํ•ด๊ฒฐํ•œ๊ฒƒ์ด ๋งŽ์•˜๋‹ค. class Solution { // ์†Œ์ˆ˜ ํŒ๋ณ„ private static int Is_Prime(int num){ int count = 0; for(int i=1; i=3) // ์•ฝ์ˆ˜๊ฐ€ 3๊ฐœ ๋„˜์–ด๊ฐ€๋ฉด ๋ฐ”๋กœ return return count; } return count; } public int solution(int[] nums){ int answer = 0; for(int i=0; i

article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ธ€์ž

HashMap์„ ์ด์šฉํ•œ๋‹ค. ๋ฌธ์ž์—ด์„ ์ˆœํšŒํ•˜๋ฉด์„œ HashMap์— (ํ•ด๋‹น ๋ฌธ์ž:์ธ๋ฑ์Šค)๋ฅผ ๋„ฃ์–ด ์ ‘๊ทผํ•œ๋‹ค. ๋งŒ์•ฝ HashMap์— ํ•ด๋‹น ๋ฌธ์ž๊ฐ€ ์ €์žฅ๋˜์ง€ ์•Š์•˜์œผ๋ฉด ํ•œ ๋ฒˆ๋„ ๋‚˜์˜จ ์ ์ด ์—†๋Š” ๋ฌธ์ž์ด๋ฏ€๋กœ answer๋ฐฐ์—ด์— -1 ์ €์žฅ ๊ทธ๋ฆฌ๊ณ  HashMap์— ํ•ด๋‹น ๋ฌธ์ž๊ฐ€ ์žˆ์œผ๋ฉด value๊ฐ’(๊ฐ€์žฅ ์ตœ๊ทผ ์ธ๋ฑ์Šค)๊ณผ ํ˜„์žฌ ๋ฌธ์ž์˜ ์ธ๋ฑ์Šค ๊ฐ’์˜ ์ฐจ์ด๋ฅผ answer ๋ฐฐ์—ด์— ์ €์žฅ import java.util.*; class Solution { public int[] solution(String s) { int[] answer = new int[s.length()]; HashMap map = new HashMap(); for(int i=0; i

article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ํฌ๊ธฐ๊ฐ€ ์ž‘์€ ๋ฌธ์ž์—ด

ํ˜•๋ณ€ํ™˜๊ณผ substring๋งŒ ์ด์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ด๊ณ , for๋ฌธ์˜ ๋ฒ”์œ„ ์„ค์ •๋งŒ ์กฐ๊ธˆ ์‹ ๊ฒฝ์“ฐ๋ฉด ๋œ๋‹ค. class Solution { public int solution(String t, String p) { int answer = 0; int len = p.length(); Long num = Long.parseLong(p); for(int i=0; i

[JAVA][์•Œ๊ณ ๋ฆฌ์ฆ˜] ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ( Greedy Algorithm )

โœ… Greedy Algorithm "๋งค ์„ ํƒ์—์„œ ์ง€๊ธˆ ์ด ์ˆœ๊ฐ„ ๋‹น์žฅ ์ตœ์ ์˜ ๋‹ต์„ ์„ ํƒํ•˜์—ฌ ์ ํ•ฉํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋„์ถœํ•˜์ž"๋ผ๋Š” ๋ชจํ† ๋ฅผ ๊ฐ€์ง„ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฌด์กฐ๊ฑด ํฐ ๊ฒฝ์šฐ๋Œ€๋กœ, ๋ฌด์กฐ๊ฑด ์ž‘์€ ๊ฒฝ์šฐ๋Œ€๋กœ, ๋ฌด์กฐ๊ฑด ๊ธด ๊ฒฝ์šฐ๋Œ€๋กœ, ๋ฌด์กฐ๊ฑด ์งง์€ ๊ฒฝ์šฐ๋Œ€๋กœ ๋“ฑ ๊ทน๋‹จ์ ์œผ๋กœ ๋ฌธ์ œ์— ์ ‘๊ทผํ•ด์•ผ ํ•œ๋‹ค๋Š” ์ ์—์„œ ์ •๋ ฌ(Sort)์ด ํ•จ๊ป˜ ์ด์šฉ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. Greedy Algorithm ์žฅ์  ํ•ญ์ƒ ์ตœ์ ์˜ ๊ฒฐ๊ณผ๋ฅผ ๋„์ถœํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ ์–ด๋Š ์ •๋„ ์ตœ์ ์˜ํ•ด์— ๊ทผ์‚ฌํ•œ ๊ฐ’์„ ๋น ๋ฅด๊ฒŒ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค. ๋˜ํ•œ ํŠน์ •ํ•œ ์ƒํ™ฉ์— ์žˆ์–ด์„œ๋Š” ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ตœ์ ์˜ ํ•ด๋ฅผ ๋ณด์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. > ์˜ˆ์‹œ 620์›์ด ์žˆ๋‹ค๋ฉด, 620์› ์ดํ•˜์˜ ๊ฐ€์žฅ ํฐ ์•ก์ˆ˜๊ฐ€ 500์›์งœ๋ฆฌ์ด๋ฏ€๋กœ ๋จผ์ € 500์›์งœ๋ฆฌ ๋™์ „์„ ํ•˜๋‚˜ ์‚ฌ์šฉํ•˜๊ณ , 120์›์ด ๋‚จ๋Š”๋‹ค...

article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด

replace ํ˜น์€ replaceAll ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•œ๋‹ค. ๋ฐฐ์—ด num๊ณผ for๋ฌธ์˜ i index๊ฐ€ ์ผ์น˜ํ•˜๋ฏ€๋กœ, ์˜๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ๋ฌธ์ž์—ด ์ˆซ์ž๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ๋งˆ์ง€๋ง‰์— ์ˆซ์ž ๋ฌธ์ž์—ด s๋ฅผ Integer.parseInt ๋กœ ์ •์ˆ˜ํ™”์‹œํ‚จ๋‹ค. class Solution { public int solution(String s) { int answer = 0; String[] num ={"zero","one","two","three","four","five","six","seven","eight","nine"}; for(int i=0; i

article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ์‹œ์ €์•”ํ˜ธ

์ฒ˜์Œ์—” ๋Œ€๋ฌธ์ž ๋ฐฐ์—ด, ์†Œ๋ฌธ์ž ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ด๋†“๊ณ  index๋ฅผ ์ด์šฉํ•ด์•ผํ–ˆ๋”๋‹ˆ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์ˆœ๊ฐ„๋ถ€ํ„ฐ ๋น„ํšจ์œจ์ ์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค. ๊ทธ๋ƒฅ ๋ฐ”๋กœ ์•„์Šคํ‚ค๋„˜๋ฒ„๋ฅผ ์ด์šฉํ•˜๋Š”๊ฒƒ์ด๋‹ค. class Solution { public String solution(String s, int n) { String answer = ""; for(int i=0; i