👨🏻💻 PS/PYTHON
[파이썬 PYTHON] LeetCode【Longest Increasing Subsequence】
class Solution(object): def lengthOfLIS(self, nums): # 원소가 들어갈 위치 찾기 def bs(sub,target): left = 0 right = len(sub)-1 while left
[파이썬 PYTHON · 자바 JAVA] 프로그래머스 【구명보트】
자바 코드 import java.util.*; class Solution { public int solution(int[] people, int limit) { int answer = 0; Arrays.sort(people); int left = 0; int right = people.length-1; while(left
[파이썬 PYTHON · 자바 JAVA] 프로그래머스 【숫자의 표현】
자바 코드 class Solution { public int solution(int n) { int answer = 0; for(int i= 1;i
[파이썬 PYTHON · 자바 JAVA] LeetCode【Coin Change】
Coin Change - LeetCode Can you solve this real interview question? Coin Change - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make leetcode.com 자바 코드 import java.util.*; class Solution { public int coinChange(int[] coins, int amount) { long[] dp = n..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Container With Most Water】
Container With Most Water - LeetCode Can you solve this real interview question? Container With Most Water - You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that toget leetcode.com 자바 코드 class Solution { public int maxArea(int[] height) { int left = 0; int right = height...
[파이썬 PYTHON · 자바 JAVA] LeetCode【3Sum】
3Sum - LeetCode Can you solve this real interview question? 3Sum - Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain du leetcode.com 자바 코드 import java.util.*; class Solution { public List threeSum(int[] nums) { Arrays.sort(nums); Set set = new H..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Search in Rotated Sorted Array】
Search in Rotated Sorted Array - LeetCode Can you solve this real interview question? Search in Rotated Sorted Array - There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1
[파이썬 PYTHON] 프로그래머스【무지의 먹방 라이브】
프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 확실히, 카카오 코테 기출문제라 그런지 어려웠다. 정확성 테스트는, 쉽게 풀 수 있었는데 효율성 테스트에서 점수 받는게 매우 힘들었고 결국 다른 사람들의 풀이를 참고했다..ㅎ import heapq def solution(food_times, k): answer = -1 # 음식 총합 보다 k가 크면 섭취할 음식이 없어지므로 -1 반환 if sum(food_times)
[파이썬 PYTHON · 자바 Java] LeetCode【Find Minimum in Rotated Sorted Array】
Find Minimum in Rotated Sorted Array - LeetCode Can you solve this real interview question? Find Minimum in Rotated Sorted Array - Suppose 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 leetcode.com 파이썬 코드 class Solution(object): def findMin(self, nums): left = 0 right = len(nums..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Maximum Product Subarray】
Maximum Product Subarray - LeetCode Can you solve this real interview question? Maximum Product Subarray - Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. Examp leetcode.com 자바 코드 class Solution { public int maxProduct(int[] nums) { int [] dp = new int[nums.length]; in..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Maximum Subarray】
Maximum Subarray - LeetCode Can you solve this real interview question? Maximum Subarray - Given an integer array nums, find the subarray with the largest sum, and return its sum. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: The subarray [4,-1,2,1] has t leetcode.com 자바 코드 class Solution { public int maxSubArray(int[] nums) { int[] dp = new int[nums.length]; dp[0]=nums..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Product of Array Except Self】
Product of Array Except Self - LeetCode Can you solve this real interview question? Product of Array Except Self - Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nu leetcode.com 자바 코드 import java.util.*; class Solution { public int[] productExceptSelf(int[] nums) { ..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Contains Duplicate】
Contains Duplicate - LeetCode Can you solve this real interview question? Contains Duplicate - Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Ex leetcode.com 파이썬 코드 class Solution(object): def containsDuplicate(self, nums): _set = set() for num in nums: if nu..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Best Time to Buy and Sell Stock】
Best Time to Buy and Sell Stock - LeetCode Can you solve this real interview question? Best Time to Buy and Sell Stock - You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosin leetcode.com 파이썬 코드 class Solution(object): def maxProfit(self, prices): buy = prices[0] ans = 0 f..
[파이썬 PYTHON · 자바 JAVA] LeetCode【Two sum】
Two Sum - LeetCode Can you solve this real interview question? Two Sum - Given 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 leetcode.com 파이썬 코드 class Solution(object): def twoSum(self, nums, target): dic = {} for i in range(len(nums)): search = ta..