๐จ๐ป๐ป PS
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐใ
์๋ฐ ์ฝ๋ class Solution { public int[] solution(String s) { int[] answer = {}; int zero = 0; int tran = 0; while(!s.equals("1")){ int numOfZero = 0; int numOfOne = 0; for(int i=0;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใ์ฌ๋ฐ๋ฅธ ๊ดํธใ
์๋ฐ ์ฝ๋ import java.util.*; class Solution { boolean solution(String s) { int result =0; for(int i=0;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์ค ใ์ต์๊ฐ ๋ง๋ค๊ธฐใ
์๋ฐ ์ฝ๋ import java.util.*; class Solution { public int solution(int []A, int []B) { int answer = 0; Arrays.sort(A); Arrays.sort(B); for(int i=0;i
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใ์ต๋๊ฐ๊ณผ ์ต์๊ฐใ
๋ฌธ์์ด์ ์ซ์ ๋ฐฐ์ด๋ก ๋ง๋ค์ด ์ค ๋ค, ์ต๋๊ฐ๊ณผ ์ต์๊ฐ์ ๊ตฌํ๋ฉด ๋๋ ๊ฐ๋จํ ๋ฌธ์ ์ด๋ค. ํ์ด์ฌ์ ๊ฒฝ์ฐ max() ์ min() ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋๊ณ ์๋ฐ๋ Math.max() ์ Math.min() ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค. ์๋ฐ ์ฝ๋ import java.util.*; import java.io.*; class Solution { public String solution(String s) { int[] arr = Arrays.stream(s.split(" ")).mapToInt(str->Integer.valueOf(str)).toArray(); int max = arr[0]; int min = arr[0]; for(int num : arr){ max = Math.max(max,num); min = Math...
[ํ์ด์ฌ PYTHON · ์๋ฐ JAVA] ํ๋ก๊ทธ๋๋จธ์คใJadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐใ
๋ฌธ์ ํฌ์ธํธ : ๋ชจ๋ ๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณํํ๋ค. ํ์ด์ฌ์ ๊ฒฝ์ฐ๋ .lower() ์๋ฐ์ ๊ฒฝ์ฐ๋ toLowerCase() ๋ฅผ ์ฌ์ฉ ๊ทธ๋ฆฌ๊ณ ์ฒซ ๋ฌธ์๋ง ์ํ๋ฒณ์ด๋ฉด ๋๋ฌธ์๋ก ์ง์ ๋ง๋ค์ด์ฃผ๊ณ , ๋๋จธ์ง๋ ๊ณต๋ฐฑ ๋ค์์ ์ค๋ ๋ฌธ์๊ฐ ์ํ๋ฒณ์ธ ๊ฒฝ์ฐ์๋ง ๋๋ฌธ์๋ก ๋ณํ์์ผ์ค๋ค. ์๋ฐ ์ฝ๋ import java.util.*; class Solution { public String solution(String s) { String answer = ""; s=s.toLowerCase(); StringBuilder sb = new StringBuilder(); for(int i=0;i
[ํ์ด์ฌ 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..