본문 바로가기

python-algorithm1422

Leetcode 1832. Check if the Sentence Is Pangram 1 2 3 4 class Solution: def checkIfPangram(self, sentence: str) -> bool: if len(set(sentence))==26: return True else: return False cs 알파벳이 적어도 1번씩은 다 쓰여야하고 중복이 있으면 안됨 2021. 8. 17.
Leetcode 1662. Check If Two String Arrays are Equivalent 1 2 3 4 5 6 7 class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: tmp1,tmp2="","" for i in word1: tmp1+=i for i in word2: tmp2+=i if tmp1==tmp2: return True else: return False Colored by Color Scripter cs 2021. 8. 17.
Leetcode 709. To Lower Case 1 2 3 4 class Solution: def toLowerCase(self, s: str) -> str: s=s.lower() return s cs 2021. 8. 17.
Leetcode 1295. Find Numbers with Even Number of Digits 1 2 3 4 5 6 class Solution: def findNumbers(self, nums: List[int]) -> int: ans=0 for i in nums: if len(str(i))%2==0: ans+=1 return ans Colored by Color Scripter cs 2021. 8. 17.
Leetcode 905. Sort Array By Parity 1 2 3 4 5 6 7 8 9 pypythonpythoclass Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: tmp=[] tmp2=[] for i in range(len( nums) ) : if nums[i]%2==0: tmp.append(nums[i]) else: tmp2.append(nums[i]) tmp.extend(tmp2) return tmp Colored by Color Scripter cs 2021. 7. 23.
Leetcode 1827. Minimum Operations to Make the Array Increasing 1 2 3 4 5 6 7 8 9 10 class Solution: def minOperations(self, nums: List[int]) -> int: ans=0 for i in range(1,len(nums)): tmp=0 if nums[i] 2021. 7. 21.
Leetcode 1323. Maximum 69 Number 1 2 3 4 5 6 7 8 9 10 11 12 class Solution: def maximum69Number (self, num: int) -> int: num=str(num) tmp=[] for i in num: tmp.append(i) for i in range(len(tmp)): if tmp[i] =='6': tmp[i]='9'; break ans='' for i in tmp: ans+=i return (int(ans)) cs 2021. 7. 21.
백준 2864 5와 6의 차이 1 2 3 4 5 6 a,b=input().split() maxa=a.replace("5","6") maxb=b.replace("5","6") mina=a.replace("6","5") minb=b.replace("6","5") print( (int(mina)+int(minb)),(int(maxa)+int(maxb))) cs 2021. 7. 20.
Leetcode 1859. Sorting the Sentence 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Solution: def sortSentence(self, s: str) -> str: tmp=list(map(str, s.split())) ans=[0]*len(tmp) nums="0123456789" for i in range (len(tmp)): for j in nums: if j in tmp[i]: tmp1=tmp[i].replace(j,"") ans[int(j)-1]=tmp1 ansStr=ans[0] for i in range(1,len(ans)): ansStr=ansStr+" "+ans[i] return ansStr cs 2021. 7. 16.
백준 3029 경고 1 2 3 4 5 6 7 8 9 10 11 12 13 a1,b1,c1=map(int, input().split(":")) a2,b2,c2=map(int, input().split(":")) ans1=a1*3600+b1*60+c1 ans2=a2*3600+b2*60+c2 if ans1>=ans2 : ans2+=3600*24 ans3=ans2-ans1 a3=ans3//3600 ans3%=3600 b3=ans3//60 ans3%=60 c3=ans3 print("%02d:%02d:%02d"%(a3,b3,c3)) cs 2021. 7. 16.
Leetcode 1913. Maximum Product Difference Between Two Pairs 1 2 3 4 class Solution: def maxProductDifference(self, nums: List[int]) -> int: nums=sorted(nums) return nums[-1]*nums[-2]-nums[0]*nums[1] cs 2021. 7. 16.
Leetcode 1486. XOR Operation in an Array 1 2 3 4 5 6 7 class Solution: def xorOperation(self, n: int, start: int) -> int: tmp=[start+2*i for i in range(n) ] ans=tmp[0] for i in range(1,len(tmp)): ans=ans^tmp[i] return ans Colored by Color Scripter cs 2021. 7. 16.