본문 바로가기

python-algorithm1422

leetcode 2485. Find the Pivot Integer https://leetcode.com/problems/find-the-pivot-integer/description/ Find the Pivot Integer - LeetCode Find the Pivot Integer - Given a positive integer n, find the pivot integer x such that: * The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such integer exists leetcode.com 1 2 3 4 5 6 7 8 9 10 class S.. 2023. 1. 10.
leetcode 2418. Sort the People https://leetcode.com/problems/sort-the-people/description/ 1 2 3 4 5 6 class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: total_list= [ [names[i],heights[i]] for i in range(len(names)) ] total_list.sort(key=lambda x: x[1], reverse=True) answer = [total_list[i][0] for i in range(len(total_list))] return answer Colored by Color Scripter cs list comprehension과 .. 2023. 1. 9.
leetcode 2315. Count Asterisks https://leetcode.com/problems/count-asterisks/description/ Count Asterisks - LeetCode Count Asterisks - You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth. Return the number of '*' in s, excluding the leetcode.com 1 2 3 4 5 6 7 class Solution: def countAste.. 2023. 1. 9.
leetcode 2367. Number of Arithmetic Triplets https://leetcode.com/problems/number-of-arithmetic-triplets/description/ 1 2 3 4 5 6 7 8 9 10 class Solution: def arithmeticTriplets(self, nums: List[int], diff: int) -> int: answer = 0 for i in range(len(nums)-2): for j in range(i+1,len(nums)-1): for k in range(j+1,len(nums)): if nums[j] - nums[i] == diff and nums[k] - nums[j] == diff: answer+=1 return answer Colored by Color Scripter cs 2023. 1. 8.
백준 10203 Count Vowels https://www.acmicpc.net/problem/10203 10203번: Count Vowels Gru has been trying to teach the minions English (they are born knowing only Minionese, which Lucy can’t stand). He is currently stuck trying to teach them the difference between vowels and consonants, which the minions are always confused about, especia www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 def sol(s): answer = s.count('a') + s.cou.. 2023. 1. 7.
leetcode 2520. Count the Digits That Divide a Number https://leetcode.com/problems/count-the-digits-that-divide-a-number/description/ 1 2 3 4 5 6 7 8 class Solution: def countDigits(self, num: int) -> int: str_num = str(num) answer = 0 for i in str_num: if num % int(i) == 0: answer+=1 return answer cs 2023. 1. 6.
leetcode 2469. Convert the Temperature https://leetcode.com/problems/convert-the-temperature/description/ Convert the Temperature - LeetCode Convert the Temperature - You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahr leetcode.com 1 2 3 4 5 6 class Solution.. 2023. 1. 6.
백준 10420 기념일 1 https://www.acmicpc.net/problem/10420 10420번: 기념일 1 세계적으로 유명한 커플 상근이와 나예는 2016년 4월 3일이 사귀기 시작한지 200일이 되는 날이었다. 상근이는 그 날이 200일인줄 몰라서 나예한테 혼났다. 이런 일이 다시는 없도록 하기 위해서 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 from datetime import date, timedelta def sol(n): start = date(2014, 4, 2) answer = start + timedelta(days=n - 1) return answer if __name__ == '__main__': n = int(input()) print(sol(n)) Colo.. 2023. 1. 4.
백준 5220 Error Detection https://www.acmicpc.net/problem/5220 5220번: Error Detection In the midst of a fierce battle, Tony Stark’s suit constantly communicates with JARVIS for technical data. This data as transmitted takes the form of 16-bit integer values. However, due to various atmospheric issues (such as those created by all of that www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 def cal(n): if bin(n.. 2023. 1. 4.
백준 16316 Baby Bites https://www.acmicpc.net/problem/16316 16316번: Baby Bites The first line of input contains an integer n (1 ≤ n ≤ 1 000), the number of bites Arild receives. Then second line contains n space-separated words spoken by Arild, the i’th of which is either a non-negative integer ai (0 ≤ ai ≤ 10 000) or the s www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 def sol(nums): for i in range(1,len(nums)+1): if nums[i-1.. 2023. 1. 4.
백준 6190 Another Cow Number Game https://www.acmicpc.net/problem/6190 6190번: Another Cow Number Game The cows are playing a silly number game again. Bessie is tired of losing and wants you to help her cheat. In this game, a cow supplies a number N (1 2023. 1. 3.
백준 16861 Harshad Numbers https://www.acmicpc.net/problem/16861 16861번: Harshad Numbers We’re all familiar with harshad numbers. For this problem, you will ... what’s that? You aren’t familiar with harshad numbers? They’re also known as Niven numbers – does that ring a bell?? Anything??? Well, it’s a simple enough concept. A harsh www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 def cal(n): answer = .. 2023. 1. 3.