본문 바로가기

python-algorithm1402

leetcode 2923. Find Champion I https://leetcode.com/problems/find-champion-i/description/ Find Champion I - LeetCode Can you solve this real interview question? Find Champion I - There are n teams numbered from 0 to n - 1 in a tournament. Given a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 2023. 12. 28.
leetcode 2697. Lexicographically Smallest Palindrome https://leetcode.com/problems/lexicographically-smallest-palindrome/description/ 1234567891011class Solution: def makeSmallestPalindrome(self, s: str) -> str: s = list(s) for i in range(len(s)//2): if s[i] != s[-(i+1)]: if s[i] 2023. 12. 28.
leetcode 2828. Check if a String Is an Acronym of Words https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words/description/ Check if a String Is an Acronym of Words - LeetCode Can you solve this real interview question? Check if a String Is an Acronym of Words - Given an array of strings words and a string s, determine if s is an acronym of words. The string s is considered an acronym of words if it can be formed by concatenatin leetc.. 2023. 12. 28.
백준 14913 등차수열에서 항 번호 찾기 https://www.acmicpc.net/problem/14913 14913번: 등차수열에서 항 번호 찾기 k가 몇 번째 항인지 출력한다. 만약, k가 주어진 a와 d로 만들어진 등차수열의 수가 아니면 "X"를 출력한다. www.acmicpc.net 1234567891011def sol(a, d, k): if (k - a) % d == 0 and (k - a) // d >= 0: return (k - a) // d + 1 else: return 'X' if __name__ == '__main__': a, d, k = map(int, input().split()) print(sol(a, d, k)) Colored by Color Scriptercs 2023. 12. 28.
leetcode 2928. Distribute Candies Among Children I https://leetcode.com/problems/distribute-candies-among-children-i/ Distribute Candies Among Children I - LeetCode Can you solve this real interview question? Distribute Candies Among Children I - You are given two positive integers n and limit. Return the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies. leetcode.com 1 2 3 4 5 6 7 8 9 .. 2023. 12. 27.
leetcode CodeTestcaseTestcaseTest Result2942. Find Words Containing Character https://leetcode.com/problems/find-words-containing-character/description/ Find Words Containing Character - LeetCode Can you solve this real interview question? Find Words Containing Character - You are given a 0-indexed array of strings words and a character x. Return an array of indices representing the words that contain the character x. Note that the returned array m leetcode.com 123456789c.. 2023. 12. 27.
leetcode 2951. Find the Peaks https://leetcode.com/problems/find-the-peaks/description/ Find the Peaks - LeetCode Can you solve this real interview question? Find the Peaks - You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array. Return an array that consists of indices of peaks in the given array in any order. Notes: * A p leetcode.com 123456789class Solution: def findPeaks(self,.. 2023. 12. 27.
leetcode 2956. Find Common Elements Between Two Arrays https://leetcode.com/problems/find-common-elements-between-two-arrays/description/ Find Common Elements Between Two Arrays - LeetCode Can you solve this real interview question? Find Common Elements Between Two Arrays - You are given two 0-indexed integer arrays nums1 and nums2 of sizes n and m, respectively. Consider calculating the following values: * The number of indices i such that leetcode.. 2023. 12. 27.
leetcode 2965. Find Missing and Repeated Values https://leetcode.com/problems/find-missing-and-repeated-values/description/ Find Missing and Repeated Values - LeetCode Can you solve this real interview question? Find Missing and Repeated Values - You are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appears twice and b which is mi leetcode.com 12345678.. 2023. 12. 27.
백준 4388 받아올림 https://www.acmicpc.net/problem/4388 4388번: 받아올림 어린이에게 여러자리 숫자의 덧셈을 가르칠 때는 오른쪽 자리부터 왼쪽으로 하나씩 계산하는 방법을 가르쳐준다. 이때, 받아올림이 발생하게 되며 아이들은 여기서 혼란에 빠진다. 받아올림이 www.acmicpc.net 12345678910111213141516171819202122def sol(n1, n2): n1 = n1.zfill(max(len(n1), len(n2)))[::-1] n2 = n2.zfill(max(len(n1), len(n2)))[::-1] answer = 0 carry = 0 for i in range(len(n1)): if int(n1[i]) + int(n2[i]) + carry >= 10: answe.. 2023. 12. 27.
백준 6550 부분 문자열 https://www.acmicpc.net/problem/6550 6550번: 부분 문자열 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 문자열 s 와 t가 빈칸을 사이에 두고 들어온다. s와 t의 길이는 10만을 넘지 않는다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 def sol(s, t): check = 0 for i in t: if s[check] == i: check += 1 if check == len(s): return 'Yes' return 'No' if __name__ == '__main__': while True: try: s, t = input().split.. 2023. 12. 23.
백준 11723 집합 https://www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import sys if __name__ == '__main__': m = int(sys.stdin.readline()) s = set() for i in range(m): operation = list(sys.stdin.readline().strip().split()) if len(operation.. 2023. 12. 23.