본문 바로가기

Python1423

leetcode 42. Trapping Rain Water https://leetcode.com/problems/trapping-rain-water/description/ Trapping Rain Water - LeetCode Trapping Rain Water - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: [https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png] Input: he leetcode.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1.. 2023. 2. 9.
백준 27389 Metronome https://www.acmicpc.net/problem/27389 27389번: Metronome A Metronome is a mechanical device used by musicians for keeping time. It is a very clever device, based on a spring, an inverted pendulum, and an escapement gear. Milo is learning to play the glockenspiel, and has purchased a metronome to help him keep ti www.acmicpc.net 1 2 3 4 5 6 7 8 def sol(n): answer = round(n/4, 2) return answer if _.. 2023. 2. 9.
백준 27433 팩토리얼 2 https://www.acmicpc.net/problem/27433 27433번: 팩토리얼 2 0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오. www.acmicpc.net 1 2 3 4 5 6 from math import factorial if __name__ == '__main__': n = int(input()) print(factorial(n)) cs 2023. 2. 9.
leetcode 5. Longest Palindromic Substring https://leetcode.com/problems/longest-palindromic-substring/description/ Longest Palindromic Substring - LeetCode Longest Palindromic Substring - Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Constraints: * 1 str: def expand(left: int, right: int) ->.. 2023. 2. 8.
백준 25630 팰린드롬 소떡소떡 https://www.acmicpc.net/problem/25630 25630번: 팰린드롬 소떡소떡 소떡소떡은 기다란 꼬치에 소세지와 떡을 끼운 음식이다. 편의상 소떡소떡을 알파벳 s와 t로만 구성된 길이 $N$의 문자열로 생각하자. 알파벳 s는 소세지를, t는 떡을 의미한다. 위 그림은 길이가 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 def sol(n, s): answer = 0 if n % 2 == 0: left, right = s[:n // 2], s[n // 2:][::-1] else: left, right = s[:n // 2], s[n // 2 + 1:][::-1] for i in range(n // 2): if left[i] !=.. 2023. 2. 8.
leetcode 49. Group Anagrams https://leetcode.com/problems/group-anagrams/description/ Group Anagrams - LeetCode Can you solve this real interview question? Group Anagrams - Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase leetcode.com 1 2 3 4 5 6 7 8 9 10 import collections clas.. 2023. 2. 7.
leetcode 819. Most Common Word https://leetcode.com/problems/most-common-word/description/ Most Common Word - LeetCode Most Common Word - Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique. The words in paragra leetcode.com 1 2 3 4 5 6 7 8 9 10 11 import re import.. 2023. 2. 7.
leetcode 937. Reorder Data in Log Files https://leetcode.com/problems/reorder-data-in-log-files/description/ Reorder Data in Log Files - LeetCode Reorder Data in Log Files - You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: * Letter-logs: All words (except the identifier) consist of lowercase English le leetcode.com 1 2 3 4 5 6 7 8 9 10 1.. 2023. 2. 7.
leetcode 1967. Number of Strings That Appear as Substrings in Word https://leetcode.com/problems/number-of-strings-that-appear-as-substrings-in-word/description/ Number of Strings That Appear as Substrings in Word - LeetCode Number of Strings That Appear as Substrings in Word - Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word. A substring is a contiguous sequence of characters withi.. 2023. 2. 3.
백준 27332 11 月 (November) https://www.acmicpc.net/problem/27332 27332번: 11 月 (November) 2022 年 11 月 3 日の 4 週間後の日は 2022 年 12 月 1 日である.この日は 2022 年 11 月ではないので 0 を出力する. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import datetime def sol(a, b): current_date = datetime.date(2022, 11, a) weeks = datetime.timedelta(weeks=b) that_day = current_date + weeks if that_day.year == 2022 and that_day.month == 11: ret.. 2023. 2. 1.
백준 27294 몇개고? https://www.acmicpc.net/problem/27294 27294번: 몇개고? 첫 번째 줄에 시간을 의미하는 정수 $T$ ($0 \le T \le 23$)와 술의 유무를 의미하는 정수 $S$ ($0 \le S \le 1$)가 공백으로 구분되어 주어진다. $T$가 $11$이하이면 아침 시간, $12$이상 $16$ 이하이면 점심 시 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 def sol(t, s): if t>=12 and t 2023. 1. 31.
백준 27328 三方比較 (Three-Way Comparison) https://www.acmicpc.net/problem/27328 27328번: 三方比較 (Three-Way Comparison) 2 つの整数 A, B が与えられる. A と B の大小を比較し,A < B ならば -1 を,A = B ならば 0 を,A > B ならば 1 を出力せよ. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def sol(a, b): if a>b: return 1 elif a == b: return 0 else: return -1 if __name__ == '__main__': a = int(input()) b = int(input()) print(sol(a, b)) cs 2023. 1. 31.