전체 글

99클럽 코테 스터디 | 비기너 | 8일차https://leetcode.com/problems/check-if-number-has-equal-digit-count-and-digit-value/description/ 접근 방법 1. dictionary를 활용하여 각 인덱스 숫자가 몇 번씩 나타나야 하는지 저장하여 '모범 답안'을 만든다. 예를 들어, 입력 값이 "1210"의 경우 해당하는 dictionary는 {0: 1, 1:2, 2: 1, 3: 0}이 된다.2. 실제로 각 인덱스 숫자가 몇 번씩 나타났는지 카운트하여 real_count에 저장한다.3. dictionary에 저장된 인덱스 출현 횟수와 real_count의 횟수를 비교하여 틀릴 경우 false를 return 한다. class Soluti..


접근 방법문제의 패턴을 단순화시켜서 접근을 해보면, n개의 숫자들의 연산에서 (n-1)개까지의 숫자들 연산 후 n번째 숫자를 더할 것이냐, 뺄 것이냐의 2가지 방법으로 분기할 수 있다. 즉, 입력 값 number가 [1, 2, 3, 4] 일 때, [1, 2, 3]의 연산 이후 마지막 숫자인 4를 더한 값과 뺀 값의 2가지 결과를 얻을 수 있다는 것이다. 이를 구현하기 위해 재귀함수를 활용할 수 있다. 전체 코드의 큰 흐름은 아래와 같다. 1. 재귀 함수의 입력값으로 array와 현재 index, 현재 sum을 받는다.2. 함수 내에서 array와 다음 index의 숫자에 대하여 sum에 더하거나 빼는 것을 반복적으로 호출한다.3. 만일 index의 값이 전체 array의 길이와 같으면, 즉 맨 마지막..


99클럽 코테 스터디 | 비기너 | 7일차 def solution(array): good_word_num = 0 for i in range(len(array)): stack = [] for j in range(len(array[i])): if stack and stack[-1] == array[i][j]: stack.pop() else: stack.append(array[i][j]) if not stack: good_word_num += 1 print(good_word_num)N = int(input())words = [input() for..

99클럽 코테 스터디 | 비기너 | 6일차https://leetcode.com/problems/climbing-stairs/description/ 접근 방법 1Queue를 사용해서 문제 해결 시도 -> Time Limit Exceeded Errorfrom collections import dequeclass Solution: def climbStairs(self, n: int) -> int: queue = deque([0]) ways = 0 while queue: current_step = queue.popleft() if current_step == n: ways += 1 e..

문제Q. 링크드 리스트의 끝에서 K번째 값을 반환하시오.[6] -> [7] -> [8] # 이런 링크드 리스트가 입력되었을 때, # 끝에서 2번째 값은 7을 반환해야 합니다! 접근 방법 11. 전체 Linked List의 길이를 구하는 함수 get_len() 함수 구현2. 특정 인덱스의 노드를 찾는 함수 get_node() 함수 구현3. 1의 함수를 이용해 구한 Linked List의 전체 길이에서 K를 빼면 찾고자 하는 노드의 인덱스가 됨4. 2의 함수를 이용해 3에서 구한 인덱스로 찾고자 하는 노드를 찾음class Node: def __init__(self, data): self.data = data s..

99클럽 코테 스터디 | 비기너 | 5일차https://leetcode.com/problems/implement-stack-using-queues/description/ from collections import dequeclass MyStack: def __init__(self): # Initilaize your data structure here self.__main_queue = deque() self.__sub_queue = deque() def push(self, x: int) -> None: # Push element x onto stack self.__main_queue.append(x) def pop(self) ..

finding_target = 2finding_numbers = [0, 3, 5, 6, 1, 2, 4]def is_exist_target_number_binary(target, array): array = sorted(array) # index setting cur_min = 0 cur_max = len(array) - 1 cur_search = (cur_min + cur_max) // 2 while cur_min target cur_max = cur_search - 1 cur_search = (cur_min + cur_max) // 2 return Falseresult = is_exist_target_number_binary(fin..

99클럽 코테 스터디 | 비기너 | 4일차 https://leetcode.com/problems/implement-queue-using-stacks/description/ class MyQueue: def __init__(self): self.list1 = [] self.list2 = [] def push(self, x: int) -> None: while self.list1: self.list2.append(self.list1.pop()) self.list1.append(x) while self.list2: self.list1.append(self.list2.pop()) def pop(..