본문 바로가기

전체 글1523

leetcode 2549. Count Distinct Numbers on Board https://leetcode.com/problems/count-distinct-numbers-on-board/description/ Count Distinct Numbers on Board - LeetCode Can you solve this real interview question? Count Distinct Numbers on Board - You are given a positive integer n, that is initially placed on a board. Every day, for 109 days, you perform the following procedure: * For each number x present on the board, f leetcode.com 1 2 3 4 5 .. 2023. 3. 7.
leetcode 1539. Kth Missing Positive Number https://leetcode.com/problems/kth-missing-positive-number/description/ Kth Missing Positive Number - LeetCode Can you solve this real interview question? Kth Missing Positive Number - Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. Return the kth positive integer that is missing from this array. Example 1: Input: leetcode.com 1 2 3 4 5 6 7 8 9 10 .. 2023. 3. 6.
leetcode 2164. Sort Even and Odd Indices Independently https://leetcode.com/problems/sort-even-and-odd-indices-independently/description/ Sort Even and Odd Indices Independently - LeetCode Can you solve this real interview question? Sort Even and Odd Indices Independently - You are given a 0-indexed integer array nums. Rearrange the values of nums according to the following rules: 1. Sort the values at odd indices of nums in non-increasing o leetcod.. 2023. 3. 3.
leetcode 203. Remove Linked List Elements https://leetcode.com/problems/remove-linked-list-elements/description/ Remove Linked List Elements - LeetCode Can you solve this real interview question? Remove Linked List Elements - Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head. Example 1: [https://assets.leetcode. leetcode.com 1 2 3 4 5 6 7 8 9 10 .. 2023. 2. 28.
leetcode 1290. Convert Binary Number in a Linked List to Integer https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/description/ Convert Binary Number in a Linked List to Integer - LeetCode Can you solve this real interview question? Convert Binary Number in a Linked List to Integer - Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the .. 2023. 2. 28.
leetcode 2574. Left and Right Sum Differences https://leetcode.com/problems/left-and-right-sum-differences/description/ 1 2 3 4 5 6 7 8 9 10 11 12 13 class Solution: def leftRigthDifference(self, nums: List[int]) -> List[int]: nums.append(0) left_sum = 0 right_sum = sum(nums) - nums[0] answer = [] for i in range(len(nums)-1): answer.append(abs(left_sum-right_sum)) left_sum+=nums[i] right_sum -= nums[i+1] return answer Colored by Color Scrip.. 2023. 2. 28.
백준 13698 Hawk eyes https://www.acmicpc.net/problem/13698 13698번: Hawk eyes 첫째 줄에 재열이가 컵을 섞는 순서가 주어진다. 이 순서는 위 그림에 있는 A, B, C, D, E, F 중 하나이다. 재열이는 컵을 최대 200번 섞는다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 if __name__ == '__main__': change = input() changes = [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]] cups = ['small', 'X', 'X', 'big'] for c in change: type_change = ord(c) - 65 start, end = changes[type_chang.. 2023. 2. 27.
백준 26575 Pups https://www.acmicpc.net/problem/26575 26575번: Pups Congratulations, you adopted some little puppies! Now you just need to go grab food for them at the store. Your vet tells you how many pounds of food each pup will eat before your next trip to the store, so you just need to calculate the total amount of fo www.acmicpc.net 1 2 3 4 5 6 if __name__ == '__main__': n = int(input()) for _ in range(n):.. 2023. 2. 27.
백준 26471 Farma https://www.acmicpc.net/problem/26741 26741번: Farma Bajtek ma farmę a na niej pewną liczbę kur i krów. Razem wszystkie te zwierzęta mają dokładnie X głów oraz Y nóg. Wszystkie kury mają po dwie nogi, a wszystkie krowy mają po cztery nogi. Oczywiście zarówno kury, jak i krowy mają po jednej g www.acmicpc.net 1 2 3 4 5 6 7 8 9 def sol(x, y): return int((4 * x - y) / 2), -int((2 * x - y) / 2) if __.. 2023. 2. 24.
백준 9771 Word Searching https://www.acmicpc.net/problem/9771 9771번: Word Searching The first line contains a single word to search. A word contains at most 20 characters. The next line and the rest is a text to search for that word. The text can contain up to 100 lines including blank lines. No line exceeds 250 characters. A word cannot www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 if __name__ == '__main__': target = i.. 2023. 2. 24.
백준 27541 末尾の文字 (Last Letter) https://www.acmicpc.net/problem/27541 27541번: 末尾の文字 (Last Letter) 葵が見た文字列 JOI の末尾の文字は G でないので,葵は末尾に文字 G を付け加えた文字列 JOIG を思い浮かべる.そのため,JOIG を出力する. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 def sol(n, s) -> str: if s[-1] == 'G': return s[:n - 1] else: return s + 'G' if __name__ == '__main__': n = int(input()) s = str(input()) print(sol(n, s)) cs 슬라이싱을 활용해서 주어진 문자열의 마지막 글자가 'G'로 끝나는지 확인하면 됩니다. Using.. 2023. 2. 24.
leetcode 232. Implement Queue using Stacks https://leetcode.com/problems/implement-queue-using-stacks/description/ Implement Queue using Stacks - LeetCode Implement Queue using Stacks - Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: * void push(int x) Pushes leetcode.com 1 2 3 4 5 6 7 8 9.. 2023. 2. 23.