Python 106

Python - Algorithm #63

Python AlgorithmLeetCode1. Two SumGiven an array of integers [nums] and an integer target, return indices of the two numbers such that they add up to target.You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answer in any order.Constraints2 ≤ nums.length ≤ 10⁴-10⁹ ≤ nums[i] ≤ 10⁹-10⁹ ≤ target ≤ 10⁹Only one valid answer ex..

Python - Algorithm #61

Python AlgorithmLeetCode49. Group AnagramsGiven an array of strings strs, group the anagrams together. You can return the answer in any order.Constraints1 ≤ strs.length ≤ 10⁴0 ≤ strs[i].length ≤ 100strs[i] consists of lowercase English letters.class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: # dictionary, key 값을 알파벳들을 정렬한 값으로 사용 d = defaultdict(list) ..

[LeetCode] 3105. Longest Strictly Increasing or Strictly Decreasing Subarray

3105. Longest Strictly Increasing or Strictly Decreasing SubarrayLeetCodehttps://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray/문제정수 배열 nums가 주어졌습니다.모든 요소가 증가하거나 감소하는 nums의 가장 긴 부분 배열의 길이를 반환하는 코드를 작성하세요.예제Input: nums = [1, 4, 3, 3, 2]Output: 2풀이 과정변수 inc와 dec를 1로 초기화합니다.변수 answer를 1로 초기화합니다.인덱스 i를 사용하여 주어진 배열 nums의 두 번째 요소부터 순회하며 다음 조건을 수행합니다.현재 요소(nums[i])가 이..