-
-
Notifications
You must be signed in to change notification settings - Fork 245
[GangBean] Week 1 #630
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
[GangBean] Week 1 #630
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e14cd76
feat: solve contains-duplicate
GangBean dfaae6c
feat: solve valid-palindrome
GangBean 9381f46
feat: solve top-k-frequent-elements
GangBean c4f4785
feat: solve longest-consecutive-sequence
GangBean 2d6c164
solve: palindrome-substrings
GangBean b58d47d
solve: house robber
GangBean 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,12 @@ | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
class Solution { | ||
public boolean containsDuplicate(int[] nums) { | ||
/*** | ||
compare length of array and length of set. | ||
O(n) given that n is length of array nums | ||
*/ | ||
return nums.length > Arrays.stream(nums).boxed().collect(Collectors.toSet()).size(); | ||
} | ||
} |
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,20 @@ | ||
class Solution { | ||
public boolean isPalindrome(String s) { | ||
/** | ||
* Step 1: Convert the input string to lowercase. -> O(n) | ||
* Step 2: Remove all non-alphanumeric characters using regex. -> O(n) | ||
* Step 3: Use two pointers to compare characters from both ends of the string. -> O(n) | ||
* Total time complexity: O(n), where n is the length of the string. | ||
*/ | ||
s = s.toLowerCase(); | ||
s = s.replaceAll("[^a-z0-9]", ""); | ||
int left = 0; | ||
int right = s.length() - 1; | ||
if (right <= 0) return true; | ||
while (left < right) { | ||
if (s.charAt(left++) != s.charAt(right--)) return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdh-92 안녕하세요! 스터디 기간 동안 잘 부탁드립니다:) 피드백주신 부분 관련 생각을 여쭤보고 싶습니다~
좋은 피드백 감사드립니다! 😄
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GangBean 안녕하세요 :) 저도 잘 부탁드립니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.