๋ถ๋ฅ ์ ์ฒด๋ณด๊ธฐ
[JAVA] 2021 KAKAO BLIND RECRUITMENT ใ๋ฉ๋ด ๋ฆฌ๋ด์ผใ
๋ฐฑํธ๋ํน์ผ๋ก ์์ ์กฐํฉ์ ๊ตฌํ ๋ค, ์์ ์กฐํฉ ๋ณ ์ฃผ๋ฌธ ํ์๋ฅผ ๊ตฌํ๋ค. (bt() ๋ฉ์๋ ์ฌ์ฉ) ์ ๊ฐ์ด ์ ๋ ฅ๋ ๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ๋งต์ ์ด์ฉํด์, ๋ฅผ ๊ตฌํ๋ค. (getMaxMenu()) ๊ทธ๋ฆฌ๊ณ ์ฝ์ค์ฌ์ด์ฆ๋ณ ์ต๋ ์ฃผ๋ฌธํ์๋ฅผ ์๊ฒ ๋์ผ๋ฏ๋ก, ์ฝ์ค ์ฌ์ด์ฆ์ ์์ ์กฐํฉ์ ๊ธธ์ด๊ฐ ์ผ์นํ๋ฉด์ [์ฃผ๋ฌธํ์์ ์ต๋ ์ฃผ๋ฌธํ์๊ฐ ์ผ์นํ ๊ฒ & 2๋ฒ ์ด์ ์ฃผ๋ฌธ ๋]๊ฒ์ Max ๊ฐ์ ๋ฆฌ์คํธ ์๋ฃ๊ตฌ์กฐ์ธ ans์ ๊ธฐ๋กํ๋ค. ์ ๋ ฌํ ๋ค, ๋ฐฐ์ด๋ก ๋ณํํด์ ๋ฐํํ๋ค import java.util.*; class Solution { HashMap map; HashMap max; List ans; StringBuilder sb; public String[] solution(String[] orders, int[] course) { map..
[JAVA] 2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด์ญ ใํํใ
๋งต๊ณผ ๋ฆฌ์คํธ๋ฅผ ํ์ฉํด์ ํ์๋ค. ๋จผ์ ์ฝ๊ฒ ์๊ฐํ ์ ์๋ ์์ด๋์ด๊ฐ, ํน์ ์ซ์๊ฐ ๋ฑ์ฅํ๋ ํ์๋ฅผ ๊ตฌํ๊ณ ๋ฑ์ฅ์ ๋ง์ด ํ๋ ์์๋ก ๋์ดํ๋ฉด ๋ต์ด ๋ ๊ฒ์ด๋ค. "{{2},{2,1},{2,1,3},{2,1,3,4}}" ์ ์์ ๋ฅผ ์์๋ก ์ค๋ช ํด๋ณด๊ฒ ๋ค. int [] result = Arrays.stream(s.replace("{","").replace("}","").split(",")) .mapToInt(Integer::valueOf) .toArray(); ์ ๋ก์ง์ ํตํด [2, 2, 1, 2, 1, 3, 2, 1, 3, 4] ์ ๊ฐ์ int ๋ฐฐ์ด๋ก ์ถ์ถํ ์ ์๋ค. ์ด ๋ฐฐ์ด์ Map์ ์ด์ฉํด์ ์นด์ดํ ์ ํ๋ค. HashMap map = new HashMap(); for(int num : result){ map..
[JAVA] 2018 KAKAO BLIND RECRUITMENT ใ์บ์ใ
ํ๋ก ๊ฐ๋จํ๊ฒ ํด๊ฒฐํ ์ ์์๋ ๋ฌธ์ , ํ๋ฅผ ์บ์ ์ ์ฅ๊ณต๊ฐ์ฒ๋ผ ์ฌ์ฉํ๋ค. ํ๊ฐ ์ ํด์ง ์บ์ ์ฌ์ด์ฆ์ ๋๋ฌํ๋ฉด, poll() ํด์ค๋ค offer() ํด์ค๋ค. ๋ง์ฝ, ์บ์ ํํธ๊ฐ ๋๋ฉด, ์ต์ ์บ์๋ก ์ ๋ฐ์ดํธ ํด์ค์ผ ํ๋ฏ๋ก remove()ํด์ค ๋ค offer() ํด์ค๋ค. ์บ์์ฌ์ด์ฆ๊ฐ 0์ธ ๊ฒฝ์ฐ์ ["LA","la"] ์ ๋ ฅ์ด ์ฃผ์ด์ง๋ฉด ๋ต์ด 10์ด ๋์์ผ ํ๋ฏ๋ก, cache ์ฌ์ด์ฆ๊ฐ 0์ธ ๊ฒฝ์ฐ๋ง ๋ฐ๋ก ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ๋ฉด ๋๋ค. import java.util.*; class Solution { Queue cache; public int solution(int cacheSize, String[] cities) { int answer = 0; cache = new LinkedList(); if(cacheSize==0){ ret..
[ํ์ด์ฌ PYTHON] ํ๋ก๊ทธ๋๋จธ์ค ใ์ผ๊ฐ ๋ฌํฝ์ดใ
def solution(n): result = [] checked = [] # ์ต์ข ๋๋ฒ final = (n) * (n + 1) // 2 # ๊ทธ๋ํ์ ๋ฐฉ๋ฌธ ์ฌ๋ถ checked ์ด๊ธฐํ for i in range(1, n + 1): arr = [j + 1 for j in range(i)] chk = [False for j in range(i)] result.append(arr) checked.append(chk) # ์์ง์ผ ์ ์๋ ๋ฐฉํฅ ์ผ์ชฝ ์๋ ๋ฐฉํฅ ๋ถํฐ ์งํ dr = [1, 0, -1] dc = [0, 1, -1] direct = 0 # 0,0 1๋ฒ ๋ถํฐ ๋๋ฒ๋ง ์์ num = 1 r, c = 0, 0 while True: # ๋๋ฒ๋ง์ด ์ต์ข ๋๋ฒ์ ๋์ผํด์ง๋ฉด ๋ฃจํ ์ข ๋ฃ if num == final: re..
[ํ์ด์ฌ PYTHON] ํ๋ก๊ทธ๋๋จธ์ค ใ๋ค์ ์๋ ํฐ ์ ์ฐพ๊ธฐใ
์ง์ง ๋๋ฌด ์ด๋ ค์ ๋ค.. ๋ฌธ์ ๋ฅผ ๊ฒจ์ฐ ์ดํดํด๋ดค๊ณ ๋ด๊ฐ ์ดํดํ ๋ฐํ์ผ๋ก ์์ ๋ฅผ ํตํด ์ค๋ช ํด๋ณด๊ฒ ๋ค. stack์ ์ฌ์ฉํ ๊ฒ์ด๊ณ , stack์๋ ๊ฐ์ด ์๋ ์ธ๋ฑ์ค๋ฅผ ๊ฐฑ์ ํด ๋๊ฐ ๊ฒ์ด๋ค. ๋จผ์ ์ฒซ๋ฒ์งธ ์์(index = 0)์ธ 9๋ ๋น๊ต๋์์ด ์์ผ๋ฏ๋ก stack์ ๊ทธ๋ฅ ์ ๋ ฅํ๋ค. stack์ index๊ฐ ์์ง ์กด์ฌํ๋ค๋ ๋ป์ ์์ง ๋ท ํฐ์๋ฅผ ๋ง๋์ง ๋ชปํ๋ค๋ ์๋ฏธ์ด๋ค. ๊ทธ ๋ค์ ๋๋ฒ์งธ ์์(index = 1)์ ๊ฐ์ด 1์ด๊ณ stack์ ํ์ธํด์ ๋ท ํฐ ์๋ก์ ์ญํ ์ ํ ์ ์๋์ง ํ์ธํด๋ณธ๋ค. ํ์ง๋ง stack์ ์ ์ฅ๋์ด ์๋ ์ธ๋ฑ์ค๋ก ๊ฐ์ ํ์ธํด๋ณด๋ 1๋ณด๋ค ํฐ 9์ด๋ฏ๋ก ์๊ฑฐํ ์ ์๋ค. stack์ ๋ณํ ์์ด index 1์ ์คํ์ ์ถ๊ฐํ๋ค. ๊ทธ ๋ค์ 3๋ฒ์งธ ์์์ธ (index = 2) 5๊ฐ ๋ท ํฐ ์ ์ญํ ์ ํ ..
[ํ์ด์ฌ PYTHON] LeetCodeใLongest Increasing Subsequenceใ
class Solution(object): def lengthOfLIS(self, nums): # ์์๊ฐ ๋ค์ด๊ฐ ์์น ์ฐพ๊ธฐ def bs(sub,target): left = 0 right = len(sub)-1 while left
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์ค ใ๊ตฌ๋ช ๋ณดํธใ
์๋ฐ ์ฝ๋ import java.util.*; class Solution { public int solution(int[] people, int limit) { int answer = 0; Arrays.sort(people); int left = 0; int right = people.length-1; while(left
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์ค ใ์ซ์์ ํํใ
์๋ฐ ์ฝ๋ class Solution { public int solution(int n) { int answer = 0; for(int i= 1;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] LeetCodeใCoin Changeใ
Coin Change - LeetCode Can you solve this real interview question? Coin Change - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make leetcode.com ์๋ฐ ์ฝ๋ import java.util.*; class Solution { public int coinChange(int[] coins, int amount) { long[] dp = n..
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] LeetCodeใContainer With Most Waterใ
Container With Most Water - LeetCode Can you solve this real interview question? Container With Most Water - You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that toget leetcode.com ์๋ฐ ์ฝ๋ class Solution { public int maxArea(int[] height) { int left = 0; int right = height...
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐใ
์๋ฐ ์ฝ๋ class Solution { public int[] solution(String s) { int[] answer = {}; int zero = 0; int tran = 0; while(!s.equals("1")){ int numOfZero = 0; int numOfOne = 0; for(int i=0;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใ์ฌ๋ฐ๋ฅธ ๊ดํธใ
์๋ฐ ์ฝ๋ import java.util.*; class Solution { boolean solution(String s) { int result =0; for(int i=0;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์ค ใ์ต์๊ฐ ๋ง๋ค๊ธฐใ
์๋ฐ ์ฝ๋ import java.util.*; class Solution { public int solution(int []A, int []B) { int answer = 0; Arrays.sort(A); Arrays.sort(B); for(int i=0;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใ์ต๋๊ฐ๊ณผ ์ต์๊ฐใ
๋ฌธ์์ด์ ์ซ์ ๋ฐฐ์ด๋ก ๋ง๋ค์ด ์ค ๋ค, ์ต๋๊ฐ๊ณผ ์ต์๊ฐ์ ๊ตฌํ๋ฉด ๋๋ ๊ฐ๋จํ ๋ฌธ์ ์ด๋ค. ํ์ด์ฌ์ ๊ฒฝ์ฐ max() ์ min() ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋๊ณ ์๋ฐ๋ Math.max() ์ Math.min() ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค. ์๋ฐ ์ฝ๋ import java.util.*; import java.io.*; class Solution { public String solution(String s) { int[] arr = Arrays.stream(s.split(" ")).mapToInt(str->Integer.valueOf(str)).toArray(); int max = arr[0]; int min = arr[0]; for(int num : arr){ max = Math.max(max,num); min = Math...
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใJadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐใ
๋ฌธ์ ํฌ์ธํธ : ๋ชจ๋ ๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณํํ๋ค. ํ์ด์ฌ์ ๊ฒฝ์ฐ๋ .lower() ์๋ฐ์ ๊ฒฝ์ฐ๋ toLowerCase() ๋ฅผ ์ฌ์ฉ ๊ทธ๋ฆฌ๊ณ ์ฒซ ๋ฌธ์๋ง ์ํ๋ฒณ์ด๋ฉด ๋๋ฌธ์๋ก ์ง์ ๋ง๋ค์ด์ฃผ๊ณ , ๋๋จธ์ง๋ ๊ณต๋ฐฑ ๋ค์์ ์ค๋ ๋ฌธ์๊ฐ ์ํ๋ฒณ์ธ ๊ฒฝ์ฐ์๋ง ๋๋ฌธ์๋ก ๋ณํ์์ผ์ค๋ค. ์๋ฐ ์ฝ๋ import java.util.*; class Solution { public String solution(String s) { String answer = ""; s=s.toLowerCase(); StringBuilder sb = new StringBuilder(); for(int i=0;i