Leetcode[day7] - Counting Elements
Given an integer array arr, count element x such that x + 1 is also in arr. If there're duplicates in arr, count them seperately. Input: arr = [1,2,3] Output: 2 Explanation: 1 and 2 are counted cause 2 and 3 are in arr. Input: arr = [1,1,3,3,5,5,7,7] Output: 0 Explanation: No numbers are counted, cause there's no 2, 4, 6, or 8 in arr. Input: arr = [1,3,2,3,5,0] Output: 3 Explanation: 0, 1 and 2 ..
Leetcode[day6] - Group Anagrams
Given an array of strings, group anagrams together. Note: All inputs will be in lowercase.The order of your output does not matter. Input: ["eat", "tea", "tan", "ate", "nat", "bat"] Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] 1. 알고리즘을 해결하기 위해서 생각한 방법 - HashMap 자료구조를 사용한다. - Key는 "eat","tea","ate"를 하나로 묶을 수 있는 sort된 단어가 필요하다. - value는 list가 들어간다. - key에 대한 value가 있다면, 해당 value인 리스트를 가..
LeetCode[day3] - Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle. Example: Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. 1. 알고리즘을 해결하기 위해서 ..