Deep_Dev
article thumbnail
[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][JAVA]Level 1 : ์ฒด์œก๋ณต

https://school.programmers.co.kr/learn/courses/30/lessons/42862 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ๋ฌธ์ œ์ž์ฒด๋Š” ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ค์šด ํŽธ์ด ์•„๋‹Œ๋ฐ.. ํžˆ๋“  ํ…Œ์ผ€์—์„œ ์˜ค๋‹ต์ด ๋งŽ์ด ๋‚˜์„œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋งŽ์ด ์ƒ๊ฐํ•ด์•ผํ•œ๋‹ค .. ๊ทธ์ค‘์— ํ•˜๋‚˜๊ฐ€ ์ผ๋‹จ ์ •๋ ฌ์„ ํ•ด์•ผํ•˜๋Š”๊ฒƒ์ด๊ณ , ๋‘๋ฒˆ ์งธ๋Š” ๋ณธ์ธ์ด ์—ฌ๋ฒŒ์˜ท์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ ๋ถ„์‹คํ•œ ๊ฒฝ์šฐ. ์ด๋Ÿด๋•Œ ๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ ์ฒด์œก๋ณต์„ ๋นŒ๋ ค์„œ ์ •์ž‘ ๋‹ค๋ฅธ์‚ฌ๋žŒ์ด ๋นŒ๋ ค์ž…์ง€ ๋ชปํ•œ๋‹ค. ์ฆ‰, ์—ฌ๋ฒŒ์˜ท์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ ๋ถ„์‹คํ•œ ํ•™์ƒ -> ๋ฐฐ์—ด์—์„œ ์ œ์™ธ์‹œํ‚ค๊ณ  answer์„ ์ฆ๊ฐ€ ์‹œ์ผœ์•ผํ•œ๋‹ค.. import java.u..

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

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