Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions contains-duplicate/renovizee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.HashMap;
import java.util.Map;

// tag renovizee 1week
// https://github.com/DaleStudy/leetcode-study/issues/217
// https://leetcode.com/problems/contains-duplicate/
class Solution {
public boolean containsDuplicate(int[] nums) {
// 시간복잡도 : O(n)
// 공간복잡도 : O(n)
Map<Integer,Integer> countMap = new HashMap<>();
for (int num : nums) {
int count = countMap.getOrDefault(num, 0);
int addCount = count + 1;
countMap.put(num, addCount);
if (addCount == 2) {
return true;
}
}
return false;
}
}

//-------------------------------------------------------------------------------------------------------------
// 기본 문법 피드백
// 1) Map 기본 문법, ~.getOrDefault()
//-------------------------------------------------------------------------------------------------------------
9 changes: 9 additions & 0 deletions house-robber/renovizee.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제에 대한 힌트는 DP 입니다!
손으로 직접 초반의 경우의 수를 계산해 보면서 특정 규칙을 찾아보시면 좋을것 같아요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

// https://github.com/DaleStudy/leetcode-study/issues/264
// https://leetcode.com/problems/house-robber/
class Solution {
public int rob(int[] nums) {

return 1;
}
}
35 changes: 35 additions & 0 deletions longest-consecutive-sequence/renovizee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.HashSet;
import java.util.Set;

// tag renovizee 1week unresolved
// https://github.com/DaleStudy/leetcode-study/issues/240
// https://leetcode.com/problems/longest-consecutive-sequence/
class Solution {
public int longestConsecutive(int[] nums) {
// 시간복잡도 : O(n)
// 공간복잡도 : O(n)

Set<Integer> numSet = new HashSet<>();
for (int num : nums) {
numSet.add(num);
}

int maxCount = 0;
for (int num : nums) {
if (numSet.contains(num - 1)) continue;
int currentCount = 1;
while (numSet.contains(num + currentCount)) {
currentCount++;
}
maxCount = Math.max(maxCount, currentCount);
}
return maxCount;
}
}


//-------------------------------------------------------------------------------------------------------------
// 기본 문법 피드백
// 1) Set<Integer> numSet = new HashSet<>();
// 2) Math 활용 Math.max(maxCount, currentCount);
//-------------------------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions top-k-frequent-elements/renovizee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// https://github.com/DaleStudy/leetcode-study/issues/237
// https://leetcode.com/problems/top-k-frequent-elements/
class Solution {
public int[] topKFrequent(int[] nums, int k) {
int[] result = {1, 2, 3};

return result;
}
}
60 changes: 60 additions & 0 deletions two-sum/renovizee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.HashMap;
import java.util.Map;

// tag renovizee 1week
// https://github.com/DaleStudy/leetcode-study/issues/219
// https://leetcode.com/problems/two-sum/description/

// #요구사항 요약
// 1. int[] nums와 int target이 주어진다.
// 2. nums의 두 수의 합이 target과 같은 int[] index를 리턴한다. (순서 상관 x)
// 3. 똑같은 원소를 두번 사용하지 못하고, 정확히 하나의 정답만 있다.

class Solution {
// Solv2: map
// 시간복잡도 : O(n)
// 공간복잡도 : O(n)
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
int[] result = new int[2];
for (int i = 0; i < nums.length; i++) {
map.put(nums[i], i);
}

for (int i = 0; i < nums.length; i++) {
int key = target - nums[i];
if (map.containsKey(key) && map.get(key) != i) {
result[0] = i;
result[1] = map.get(key);
}
}
return result;

}
//-------------------------------------------------------------------------------------------------------------
// Solv1: Brute Force
// 시간복잡도 : O(n^2)
// 공간복잡도 : O(1)
// public int[] twoSum(int[] nums, int target) {
// int size = nums.length;
// for(int i = 0; i < size - 1; i++) {
// for(int j = i+1; j < size; j++) {
// if(target == (nums[i] + nums[j])){
// return new int[]{i,j};
// }
// }
// }
// return new int[]{};
// }


// 1) ==: 두 값이 같은지 비교. 기본 타입은 값을 비교하고, 참조 타입은 메모리 주소(동일한 객체인지)를 비교
// 참조 타입 객체의 내용이 같은지를 비교하려면 주로 a.equals(b)를 사용
//
// 2) 초기화 배열과 맵
// - new int[2] :size 초기화
// - new int[]{1,2,3} : 실제 값 초기화
// - Map<String,String> test = new HashMap<>(); 맵의 k/v 타입은 앞 변수에 설정한다. val 만사용하다..
//-------------------------------------------------------------------------------------------------------------

}