본문 바로가기

python-algorithm1402

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.
leetcode 739. Daily Temperatures https://leetcode.com/problems/daily-temperatures/description/ Daily Temperatures - LeetCode Can you solve this real interview question? Daily Temperatures - Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer leetcode.com 1 2 3 4 5 6 7 8 9 10 11 class Solutio.. 2023. 2. 23.
leetcode 316. Remove Duplicate Letters https://leetcode.com/problems/remove-duplicate-letters/description/ Remove Duplicate Letters - LeetCode Can you solve this real interview question? Remove Duplicate Letters - Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible re leetcode.com 1 2 3 4 5 6 7 8 9 10 11 .. 2023. 2. 23.
leetcode 20. Valid Parentheses https://leetcode.com/problems/valid-parentheses/description/ Valid Parentheses - LeetCode Can you solve this real interview question? Valid Parentheses - Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the sam leetcode.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 cl.. 2023. 2. 23.
백준 9773 ID Key https://www.acmicpc.net/problem/9773 9773번: ID Key บรรทัดแรกคือค่า N (1 ≤ N ≤ 100) ระบุจํานวนคน และ N บรรทัดต่อมา แต่ละบรรทัดคือเลขประจําตัวประชาชน 13 ห www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 def sol(s) -> int: first, last_three_number = 0, 0 for i in s: first += int(i) last_three_number = int(s[-3] + s[-2] + s[-1]) * 10 answer = first + last_three_number if first + answer 2023. 2. 21.