본문 바로가기

LeetCode342

leetcode 2529. Maximum Count of Positive Integer and Negative Integer https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/description/ Maximum Count of Positive Integer and Negative Integer - LeetCode Maximum Count of Positive Integer and Negative Integer - Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers. * In other words, if the numb.. 2023. 1. 10.
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.
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.
leetcode 2413. Smallest Even Multiple 1 2 3 4 5 6 class Solution: def smallestEvenMultiple(self, n: int) -> int: if n%2==0: return n else : return n*2 cs 이 문제는 정수를 입력받으면 2와 그 정수의 최소 공배수를 구하면 됩니다. 다만 유클리드 호제법(https://ko.wikipedia.org/wiki/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C_%ED%98%B8%EC%A0%9C%EB%B2%95)을 통해 구할수도 있지만 해당 문제는 주어진 정수가 홀수이냐 짝수이냐에 따라 조건문만 나누면 되서 더 쉽습니다 2022. 9. 22.
leetcode 557. Reverse Words in a String III 1 2 3 4 5 6 7 8 class Solution: def reverseWords(self, s: str) -> str: s=s.split() output=s[0][::-1] for i in range(1, len(s)): output+=' ' output+=s[i][::-1] return output cs 이번 문제는 leetcode 문제인데요 리트코드는 다른 문제에 비해 사족이 짧아 자주 애용합니다. 문자열을 입력받고 ' ' whitespalce 기준으로 나누고 나뉜 문자열의 역을 다시 붙여 출력하면 됩니다. s = "Let's take LeetCode contest" s=s.split() print(s) 테스트해보다가 신기한게 나와서 공유드려요 위 그림의 리스트에서 차이점이 바로 보이실까요? .. 2022. 9. 22.
leetcode 1050. Actors and Directors Who Cooperated At Least Three Times 1 2 3 4 5 # Write your MySQL query statement below select actor_id, director_id from ActorDirector group by actor_id, director_id having count(actor_id)>=3 cs 2022. 7. 26.
leetcode 1702A - Round Down the Price + 1 2 3 4 5 def sol(n): n_len=len(str(n)) return n-10**(n_len-1) for i in range(int(input())): print(sol(int(input()))) cs 2022. 7. 19.
leetcode 1702B - Polycarp Writes a String from Memory 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 def sol(s): cnt=0 days=1 string_list = [] for i in s: if i in string_list: pass else : if cnt>=3: cnt=0 days+=1 string_list = [] string_list.append(i) cnt+=1 return days for i in range(int(input())): print(sol(input())) cs 2022. 7. 19.