본문 바로가기

전체 글

[Leetcode/파이썬] 162. Find Peak Element Find Peak ElementA peak element is an element that is strictly greater than its neighbors.Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the.. 더보기
[Leetcode/파이썬] 190. Reverse Bits Reverse BitsReverse bits of a given 32 bits unsigned integer.Note:Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.In Java, the compiler represents the sig.. 더보기
[Leetcode/파이썬] 3. Longest Substring Without Repeating Characters Longest Substring Without Repeating CharactersGiven a string s, find the length of the longest substring without duplicate characters. Example 1:Input: s = "abcabcbb"Output: 3Explanation: The answer is "abc", with the length of 3.Example 2:Input: s = "bbbbb"Output: 1Explanation: The answer is "b", with the length of 1.Example 3:Input: s = "pwwkew"Output: 3Explanation: The answer is "wke", with t.. 더보기
[Leetcode/파이썬] 153. Find Minimum in Rotated Sorted Array Find Minimum in Rotated Sorted ArraySuppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:[4,5,6,7,0,1,2] if it was rotated 4 times.[0,1,2,4,5,6,7] if it was rotated 7 times.Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]]... 더보기
[Leetcode/파이썬] 27. Remove Element Remove ElementGiven an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:Change the array nums such that the first k elemen.. 더보기
[Leetcode/파이썬] 5. Longest Palindromic Substring Longest Palindromic SubstringGiven a string s, return the longest palindromic substring in s. Example 1:Input: s = "babad"Output: "bab"Explanation: "aba" is also a valid answer.Example 2:Input: s = "cbbd"Output: "bb" Constraints:1 s consist of only digits and English letters. class Solution: def longestPalindrome(self, s: str) -> str: left = right = 0 for i in range(len(s)) : .. 더보기
[Leetcode/파이썬] 373. Find K Pairs with Smallest Sums Find K Pairs with Smallest SumsYou are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k.Define a pair (u, v) which consists of one element from the first array and one element from the second array.Return the k pairs (u1, v1), (u2, v2), ..., (uk, vk) with the smallest sums. Example 1:Input: nums1 = [1,7,11], nums2 = [2,4,6], k = 3Output: [[1,2],[1,4],[1,6].. 더보기
[Leetcode/파이썬] 26. Remove Duplicates from Sorted Array Remove Duplicates from Sorted ArrayGiven an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things:Chan.. 더보기