LeetCode

Algorithm/PTUStudy

4주차. 배열(자신을 제외한 배열의 곱)

11. 자신을 제외한 배열의 곱 https://leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - LeetCode 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 nums is guaranteed to fit in a 32-bit integer. leetcode.com 📌문제 배열을 입력..

Algorithm/PTUStudy

4주차. 배열(배열파티션1)

10. 배열 파티션1 https://leetcode.com/problems/array-partition/ Array Partition - LeetCode Array Partition - Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum. Example 1: Input: nums = [1,4,3,2] Outpu leetcode.com 📌문제 n개의 페어를 이용한 min(a, b)의 합으로 만들 수 있는 가장 큰 수..

Algorithm/PTUStudy

3주차. 배열(세수의 합)

09. 세수의 합 https://leetcode.com/problems/3sum/ 3Sum - LeetCode 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 duplicate triplets. Example 1: Input: nums leetcode.com 📌문제 배열을 입력받아 합으로 0을 만들 수 있는 3개의 엘리먼트를 출력하라 - 예제1 📝입력 nums = [-1,0,1,2,..

Algorithm/PTUStudy

3주차. 배열(빗물 트래핑)

08. 빗물 트래핑 https://leetcode.com/problems/trapping-rain-water/ Trapping Rain Water - LeetCode Trapping Rain Water - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: [https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png] Input: he leetcode.com 📌문제 높이를 입력받아 비 온 후 얼마나 많은 물이 쌓일 수 있는지 ..

Algorithm/PTUStudy

3주차. 배열(두수의 합)

07. 두수의 합 https://leetcode.com/problems/two-sum/ Two Sum - LeetCode 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 use the same element twice. You can return leetcode.com 📌문제 덧셈하여 타겟을 만들 수 있는 배열의 두 인덱스를 리턴하라 - 예제1 📝입력 nums = [2,7,11,..

Algorithm/PTUStudy

2주차. 문자열 조작(그룹 애너그램)

04. 그룹 애너그램 📌문제 문자열 배열을 받아 애너그램 단위로 그룹핑하라 - 예제1 📝입력 `strs = ["eat","tea","tan","ate","nat","bat"]` 💻출력 `[["bat"],["nat","tan"],["ate","eat","tea"]]` - 예제2 📝입력 `strs = [""]` 💻출력 `[[""]]` 📌풀이 1. Map을 활용한 방법 (7ms, 45.4mb) public List groupAnagrams(String[] strs) { Map map = new HashMap(); for(String s : strs){ char[] charArr = s.toCharArray(); Arrays.sort(charArr); String key = String.valueOf(charA..

Algorithm/PTUStudy

2주차. 문자열 조작(가장 흔한 단어)

03. 가장 흔한 단어 📌문제 금지된 단어를 제외한 가장 흔하게 등장하는 단어를 출력하라. 대소문자 구분을 하지 않으며, 구두점(마침표, 쉼표 등) 또한 무시한다. - 예제1 📝입력 `paragraph = "Bob hit a ball, the hit BALL flew far after it was hit." banned = ["hit"]` 💻출력 `"ball"` - 예제2 📝입력 `paragraph = "a.", banned = []` 💻출력 `"a"` 📌풀이 1. Map과 Set을 활용한 방법 (12ms, 42.5mb)⭐ public String mostCommonWord(String paragraph, String[] banned) { String answer = ""; Map map = new Ha..

Algorithm/PTUStudy

1주차. 문자열 조작(로그파일 재정렬)

03. 로그파일 재정렬 📌문제 로그를 재정렬하라. 기준은 다음과 같다. >1. 로그의 가장 앞 부분은 식별자다. 2. 문자로 구성된 로그가 숫자 로그보다 앞에 온다. 3. 식별자는 순서에 영향을 끼치지 않지만, 문자가 동일한 경우 식별자 순으로 한다. 4. 숫자 로그는 입력 순서대로 한다. - 예제1 📝입력 `["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]` 💻출력 `["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]` - 예제2 📝입력 `["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key ..

지구우중
'LeetCode' 태그의 글 목록 (3 Page)