Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions contains-duplicate/eunhwa99.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> seen = new HashSet<>();
for (int num : nums) {
if (!seen.add(num)) {
return true;
}
}

return false;


}
}
24 changes: 24 additions & 0 deletions house-robber/eunhwa99.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.util.Arrays;

class Solution {
int size = 0;
int[] numArray;
int[] dp;

public int rob(int[] nums) {
size = nums.length;
dp = new int[size];
// 배열의 모든 값을 -1로 변경
Arrays.fill(dp, -1);
numArray = nums;
return fun(0);
}

private int fun(int idx) {
if (idx >= size) return 0;
if (dp[idx] != -1) return dp[idx];
dp[idx] = 0; // check
dp[idx] += Math.max(fun(idx + 2) + numArray[idx], fun(idx + 1));
return dp[idx];
}
}
23 changes: 23 additions & 0 deletions longest-consecutive-sequence/eunhwa99.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.HashSet;

class Solution {
public int longestConsecutive(int[] nums) {
HashSet<Integer> mySet = new HashSet<Integer>();

for (int num : nums) {
mySet.add(num);
}

int result = 0;
for (int num : mySet) {
int cnt = 1;
if (!mySet.contains(num - 1)) {
while (mySet.contains(++num)) {
++cnt;
}
result = Math.max(cnt, result);
}
}
return result;
}
}
16 changes: 16 additions & 0 deletions top-k-frequent-elements/eunhwa99.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.HashMap;
import java.util.Map;
class Solution {
public static int[] topKFrequent(int[] nums, int k) {
Map<Integer, Integer> myMap = new HashMap<>();
for (int num : nums) {
myMap.put(num, myMap.getOrDefault(num, 0) + 1);
}
return myMap.entrySet()
.stream()
.sorted((v1, v2) -> Integer.compare(v2.getValue(),v1.getValue()))
.map(Map.Entry::getKey)
.mapToInt(Integer::intValue)
.toArray();
}
}
23 changes: 23 additions & 0 deletions valid-palindrome/eunhwa99.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public boolean isPalindrome(String s) {
StringBuilder str = new StringBuilder();

for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isLetterOrDigit(c)) {
str.append(Character.toLowerCase(c));
}
}

int left = 0, right = str.length() - 1;
while (left < right) {
if (str.charAt(left) != str.charAt(right)) {
return false;
}
left++;
right--;
}

return true;
}
}
Loading