분류 전체보기 (73) 썸네일형 리스트형 LeetCode-383 Ransom Note 파이썬 풀이 Ransom Note - LeetCode Can you solve this real interview question? Ransom Note - Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ranso leetcode.com 문제 문자열 magazine에 있는 문자들을 조합하여 ransomeNote 문자열을 만들 수 있는지 판별하는 문제입니다. magazine에 있는 문자들을 중복해서 사용할 수는 없습니다. 풀.. LeetCode-219 Contains Duplicate II 파이썬 풀이 Contains Duplicate II - LeetCode Can you solve this real interview question? Contains Duplicate II - Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) bool: for i in range(0,len(nums)-1): if nums[i] in nums[i+1:]: j = nums.index(nums[i],i+1) if abs(i-j) bool: if len(set(nums)) == len(nums):.. LeetCode-1 Two Sum 파이썬 풀이 https://leetcode.com/problems/two-sum/submissions/1037103270/?envType=study-plan-v2&envId=top-interview-150 문제 int형 배열 num가 주어졌을 때, 더했을 때 target이 되는 두 요소의 인덱스를 반환하는 문제입니다. 요소를 중복 사용하는 것은 안됩니다. 풀이 1. nums를 돌면서 target - 해당 위치의 요소 한 값과 동일한 요소가 nums에 존재하는지 찾습니다. 2. 지나간 위치는 이미 확인하여서 고려할 필요가 없으므로 현재 찾는 위치의 뒷부분의 배열에서만 찾으면 됩니다. 3. 만약 target - nums[i] 한 값과 동일한 요소를 찾았다면 해당 인덱스와 i를 반환합니다. class Solution: d.. LeetCode-155 MinStack 파이썬 풀이 문제 스택을 구현하는 간단한 문제입니다. __init__ 에선 stack의 초기화를 push에선 stack에 데이터 추가를, pop에선 stack의 맨 위에 값을 제거하도록 구현해야 합니다. top에선 stack의 맨 위에 값을 반환하고, getMin에선 현재 stack의 데이터 중 가장 작은 값을 반환하면 됩니다. 풀이 1. __init__ stack으로 쓰일 배열과, 스택의 가장 상단 인덱스를 의미하는 topV를 초기화합니다. topV는 아직 stack에 입력된 값이 없기에 -1로 설정합니다. 2. push stack안에 데이터를 push할 때마다 top을 +1 합니다. +1한 인덱스의 위치에 데이터를 저장합니다. 3. pop stack의 상단의 데이터를 제거해야하므로 top이 -1이 아닌 경우에만 .. LeetCode-141 Linked List Cycle 파이썬 풀이 Linked List Cycle - LeetCode Can you solve this real interview question? Linked List Cycle - Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuo leetcode.com 문제 주어진 링크드 리스트가 순환하는지 순환하지 않는지를 판단하는 문제입니다. 풀이 싸이클이 있는 링크드 리스트의 특성을 알고 있으면 쉽게 풀 수 있는데, 이동하는 크기가 다른 .. LeetCode-209 Minimum Size Subarray Sum 파이썬 풀이 Minimum Size Subarray Sum - LeetCode Can you solve this real interview question? Minimum Size Subarray Sum - Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarr leetcode.com 문제 양수인 int형 배열 nums에서 target 보다 크거나 같은 값이 되기 위해선 최소한 몇개의 요소가 필요한지 계산하는 문제이다. 풀이 문제를 처음 보고 한.. LeetCode-74 Search a 2D Matrix 파이썬 풀이 Search a 2D Matrix - LeetCode Can you solve this real interview question? Search a 2D Matrix - You are given an m x n integer matrix matrix with the following two properties: * Each row is sorted in non-decreasing order. * The first integer of each row is greater than the last integer leetcode.com 문제 이차원 배열안에서 target값이 존재하는 지를 찾는 문제 입니다. 풀이 단순히 이차원 배열을 한행씩 쪼개어 in 연산을 통해 쉽게 해결하였습니다. 각 행의 순서가 오름차순.. LeetCode-35 Search Insert Position 파이썬 풀이 Search Insert Position - LeetCode Can you solve this real interview question? Search Insert Position - Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must w leetcode.com 문제 정렬된 int형 배열에서 target과 같은 값이 있다면 해당 값이 위치하는 인덱스를, 없다면 target이 어느 인덱스에 들어가야 하는 지를 반환하는 문제입니다. .. 이전 1 ··· 3 4 5 6 7 8 9 10 다음