분류 전체보기

    크레인 인형 뽑기 →"열"접근★★ + 전부 1씩 빼주기(람다식)★★

    나의 풀이 def solution(board, moves): stack=[] cnt=0 #j는 열(column)을 의미한다. #len(board)는 행의 갯수를 의미한다. #move리스트에서 1은 0열(column)을 의미한다. 5는 4열(column)을 의미한다. for j in range(len(moves)): for i in range(len(board)): # print(board[i][moves[j]-1]) 열단위로 접근한다. if board[i][moves[j]-1] !=0: #stack processing stack.append(board[i][moves[j]-1]) board[i][moves[j]-1]=0 #스택에 동일한 값인지 아닌지 확인을 한다. if len(stack)>=2 and s..

    폰켓몬→ boxed()★+ collectingAndThen()

    나의 풀이 import java.util.*; class Solution { public int solution(int[] nums) { int choice_cnt = nums.length/2; Integer[] arr = Arrays.stream(nums).boxed().toArray(Integer[]::new); Set set = new HashSet(Arrays.asList(arr)); int kind_cnt=set.size(); if(choice_cnt>kind_cnt){ return kind_cnt; } else{ return choice_cnt; } } } 다른 사람의 풀이 import java.util.Arrays; import java.util.stream.Collectors; class ..

    폰켓몬★★ → 해설, 조합X

    나의 풀이 def solution(nums): choice_cnt = int(len(nums)//2) kind_cnt = len(set(nums)) if choice_cnt > kind_cnt: return kind_cnt else: return choice_cnt ▶ ex1) nums=[1,2,3,4,5,5,5,5] 라면 전체 포켓몬의 종류의 수(kind_cnt)는 [1,2,3,4,5] =>총 5종류가 된다. ▶ choice_cnt=len(nums)//2=총 마리수//2) ▶ 하지만 최대 가져갈 수 있는 포켓몬은 최대 8마리 중 절반인 4마리(choice_cnt) 이므로 결국엔 4종류 밖에 선택이 안된다. 따라서 4를 return해야 한다. (kindcnt>choicecnt) ▶ ex2) nums=[1..

    키패드 누르기★★

    다른 사람의 풀이 class Solution { //0부터 9까지 좌표 {y,x} int[][] numpadPos = { {3,1}, //0 {0,0}, //1 {0,1}, //2 {0,2}, //3 {1,0}, //4 {1,1}, //5 {1,2}, //6 {2,0}, //7 {2,1}, //8 {2,2} //9 }; //초기 위치 int[] leftPos = {3,0}; int[] rightPos = {3,2}; String hand; public String solution(int[] numbers, String hand) { this.hand = (hand.equals("right")) ? "R" : "L"; String answer = ""; for (int num : numbers) { Str..