LeetCode342 Leetcode 1822. Sign of the Product of an Array 1 2 3 4 5 6 7 8 pythonclass Solution: def arraySign(self, nums: List[int]) -> int: cnt=1 for i in nums: cnt*=i if cnt>0 : return 1 elif cnt ==0 : return 0 else : return -1 cs 문제 자체가 크게 어렵지 않아요 입력받은 리스트의 하나하나 곱한것의 부호 에 따라서 리턴해주면 되는 문제입니다. 2021. 8. 19. Leetcode 344. Reverse String 1 2 3 4 5 6 class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ s.reverse() Colored by Color Scripter cs 내장함수 reverse() 쓰면됩니당 2021. 8. 17. 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. 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. 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. 이전 1 ··· 23 24 25 26 27 28 29 다음