전체 글(221)
-
[LeetCode] Remove Element (Python)
class Solution: def removeElement(self, nums: List[int], val: int) -> int: i = 0 for j in range(len(nums)): if nums[j] != val: nums[i] = nums[j] i += 1 return i
2024.02.27 -
[LeetCode] Merge Sorted Array (Python)
class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: N1 = nums1[:m] N2 = nums2[:n] for i in range(len(N2)): N1.append(N2[i]) num1 = sorted(N1) for i in range(len(num1)): nums1[i] = num1[i] """ Do not return anything, modify nums1 in-place instead. """
2024.02.27 -
[LeetCode] Duplicate Zeros (Python)
class Solution: def duplicateZeros(self, arr: List[int]) -> None: temp = [] for i in range(len(arr)): if arr[i] == 0: temp.append(arr[i]) temp.append(arr[i]) answer = temp[:len(arr)] for i in range(len(arr)): arr[i] = answer[i]
2024.02.27 -
[LeetCode] Squares of a Sorted Array (Python)
class Solution: def sortedSquares(self, nums: List[int]) -> List[int]: square = [] for i in range(len(nums)): square.append(nums[i]**2) square = sorted(square) return square
2024.02.27 -
[LeetCode] Find Numbers with Even Number of Digits (Python)
class Solution: def findNumbers(self, nums: List[int]) -> int: res = 0 for i in range(len(nums)): if len(str(nums[i])) % 2 == 0: res += 1 return res
2024.02.27 -
[LeetCode] Max Consecutive Ones (Python)
class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) -> int: maximum = 0 temp = 0 for i in range(len(nums)): if nums[i] == 1: temp += 1 else: maximum = max(maximum, temp) temp = 0 return max(maximum, temp)
2024.02.27