-
-
Notifications
You must be signed in to change notification settings - Fork 245
[minji-go] Week 1 #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[minji-go] Week 1 #649
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ae9ff7
feat: contains duplicate
minji-go 4d964a9
feat: valid palindrome
minji-go 5dd3628
refactor: 개행문자
minji-go 6ae4bbe
feat: top k frequent elements
minji-go 0d5334c
feat: longest consecutive sequence
minji-go ec729e1
feat: house robber
minji-go fe2f86d
refactor: complexity 추가, 공간복잡도 개선
minji-go 7fbc074
refactor: 개행문자 추가
minji-go File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Solution { | ||
public boolean containsDuplicate(int[] nums) { | ||
Set<Integer> count = new HashSet<>(); | ||
boolean answer = false; | ||
for(int num : nums){ | ||
if(count.contains(num)) { | ||
answer = true; | ||
break; | ||
} | ||
count.add(num); | ||
} | ||
return answer; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Solution { | ||
public int rob(int[] nums) { | ||
int[] sum = new int[nums.length+1]; | ||
sum[0] = nums[0]; | ||
if(nums.length>1) sum[1] = Math.max(nums[0], nums[1]); | ||
for(int i=2; i<nums.length; i++){ | ||
sum[i]=Math.max(nums[i]+sum[i-2],sum[i-1]); | ||
} | ||
return sum[nums.length-1]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Solution { | ||
public int longestConsecutive(int[] nums) { | ||
Set<Integer> set = new HashSet<>(); | ||
for(int num: nums) { | ||
set.add(num); | ||
} | ||
|
||
int answer = 0; | ||
for(int num: nums){ | ||
if(set.contains(num-1)){ | ||
continue; | ||
} | ||
int length = 1; | ||
while (set.contains(num+length)){ | ||
length++; | ||
} | ||
answer = Math.max(answer, length); | ||
} | ||
|
||
return answer; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Solution { | ||
public int[] topKFrequent(int[] nums, int k) { | ||
Map<Integer, Integer> count = new HashMap<>(); | ||
for(int num : nums){ | ||
count.put(num, count.getOrDefault(num, 0)+1); | ||
} | ||
List<Integer> tops = count.keySet().stream() | ||
.sorted((i1, i2) -> count.get(i2)-count.get(i1)) | ||
.limit(k) | ||
.toList(); | ||
|
||
int[] answer = new int[k]; | ||
for(int i=0; i<k; i++) { | ||
answer[i] = tops.get(i); | ||
} | ||
return answer; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Solution { | ||
public boolean isPalindrome(String s) { | ||
String regex ="[^A-Za-z0-9]"; | ||
String palindrome = s.replaceAll(regex,"").toLowerCase(); | ||
minji-go marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
boolean answer = true; | ||
for(int i=0; i<palindrome.length()/2; i++){ | ||
if(palindrome.charAt(i) != palindrome.charAt(palindrome.length()-1-i)) { | ||
answer = false; | ||
break; | ||
} | ||
} | ||
return answer; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.