Problem Solving/LeetCode(27)
-
[LeetCode] 561. Array Partition I
https://leetcode.com/problems/array-partition-i/ Array Partition I - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 1 class Solution: def arrayPairSum(self, nums: List[int]) -> int: nums.sort(reverse=True) sum = 0 for i in range(1, len(nums), 2): sum += nums[i] return sum 내림차..
2021.01.10 -
[LeetCode] 15. 3Sum
https://leetcode.com/problems/3sum/ 3Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 from typing import List class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: if len(nums) < 3: return [] triplets = [] nums.sort() for i in range(len(nums) - 2): if i ..
2021.01.10 -
[LeetCode] 1. Two Sum
https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 1 class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: index = [] for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] + nums[j] == target:..
2021.01.07 -
[LeetCode] 5. Longest Palindromic Substring
https://leetcode.com/problems/longest-palindromic-substring/ Longest Palindromic Substring - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 class Solution: def longestPalindrome(self, s: str) -> str: if len(s) < 2 or s[:] == s[::-1]: return s palindrome = [] length = len(s) s..
2021.01.07 -
[LeetCode] 49. Group Anagrams
https://leetcode.com/problems/group-anagrams/ Group Anagrams - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: anagrams = [] sorted_words = [] for word in strs: sorted_words.append(sorted(','.join(wor..
2021.01.06 -
[LeetCode] 819. Most Common Word
https://leetcode.com/problems/most-common-word/ Most Common Word - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 import collections import re from typing import OrderedDict class Solution: def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: word_dic = {} sort..
2021.01.05