Cute Running Puppy
반응형

leetcode 7

[python] 238. Product of Array Except Self

Product of Array Except Self - LeetCode Product of Array Except Self - 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 자신을 제외한 배열의 곱 제시된 배열에서 자신을 제외한 값들을 곱한 값들을 리턴하는 문제 주의!! 나눗셈 금지 조건 존재 배열의 모든 값들의 곱을 구하고 자기 자신으로 나누는 풀이는 불가! 풀이 옳은 풀이 자기 자신을 제외한 왼쪽 값들의 곱셈 결과와 오른쪽 값들의 곱을 곱하면 올바른 풀이를 ..

[python] 561. Array Partition

Array Partition - LeetCode Array Partition - 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 주어진 배열에서 2개의 값으로 이루어진 페어를 생성하고 페어의 값의 최솟값들의 합이 최대가 될 때의 합을 리턴하는 문제 정말로 모든 페어를 구한다 ? -> x 페어의 최소값들의 합이 최대가 되어야 한다는 조건을 이용하여 페어를 구해보자 풀이 오름차순 풀이 2개의 원소를 가진 값들의 최솟값의 합을 구해야 한다 그러나 모든 ..

[python] 15. 3sum

3Sum - LeetCode 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 세 수의 합 입력받은 숫자 배열에서 세 수를 더하여 0이 되는 3수의 조합을 반환하는 문제 풀이 브루트 포스 모든 수를 조합하여 더하여 합이 0이 되는 조합을 찾으면 풀이할 수 있다. # 브루트 포스 # Time Limit Exceeded from typing import List class Solution: def threeSum(self, nums: List[int]) -..

[python] 1. Two Sum

Two Sum - LeetCode 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 두 수의 합 더하여 target의 값이 되는 두 값의 인덱스를 반환하는 문제 매우 쉬운 문제이나 여러 가지 방법으로 풀이할 수 있어 코딩 인터뷰에서 높은 빈도로 출제되는 문제이다. 풀이 다양한 방법으로 풀이가 가능한 문제이다. 브루트 포스로 풀이 브루트 포스 (brute-force): 무차별 대입 방식 모든 조합을 다 더해서 일일이 확인해본다면 브루트 포스 방식을 ..

[python]5. Longest Palindromic Substring

Longest Palindromic Substring - LeetCode 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 가장 긴 팰린드롬 부분 문자열 입력된 문자열에서 가장 긴 팰린드롬을 찾아 반환하는 문제 1. 팰린드롬을 찾고 2. 가장 긴 팰린드롬인지 확인 틀린 풀이 class Solution: def longestPalindrome(self, s: str) -> str: # 팰린드롬을 담을 리스트 p..

[python] 344. Reverse String

https://leetcode.com/problems/reverse-string/ Reverse String - 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 문자열을 뒤집는 문제 (return을 사용하면 안된다) 풀이 1. class Solution: def reverseString(self, s: List[str]) -> None: s.reverse() reverse 함수를 사용 (reverse 함수는 리스트에만 적용가능) (결과) Runtime: 379 m..

[python] 125. Valid Palindrome

https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - 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 isPalindrome(self, s: str) -> bool: s = ''.join(char for char in s if char.isalpha(..