-
-
Notifications
You must be signed in to change notification settings - Fork 245
[gmlwls96] Week1 #662
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
[gmlwls96] Week1 #662
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5aaca99
[week1] contains-duplicate - hjtag.kt
gmlwls96 96a9820
Merge branch 'DaleStudy:main' into main
gmlwls96 8887ab8
이름 수정
gmlwls96 1774ef3
[week1] valid-palindrome - gmlwls96
gmlwls96 ce6a63e
[week1] Top K Frequent Elements - gmlwls96
gmlwls96 912848a
줄바꿈 누락 처리 수정
gmlwls96 c299218
[week1] Longest-consecutive-sequence - gmlwls96
gmlwls96 4247144
[week1] House Robber - gmlwls96
gmlwls96 67d0f73
[Week1] House Robber 수정.
gmlwls96 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,7 @@ | ||
package leetcode_study | ||
|
||
class Solution { | ||
fun containsDuplicate(nums: IntArray): Boolean { | ||
return nums.toSet().size != nums.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,16 @@ | ||
package leetcode_study | ||
|
||
import java.lang.Integer.max | ||
|
||
class Solution { | ||
fun rob(nums: IntArray): Int { | ||
return max(rob_recursion(nums, 0), rob_recursion(nums, 1)) | ||
} | ||
|
||
private fun rob_recursion(nums: IntArray, index: Int): Int { | ||
if (index >= nums.size) { | ||
return 0 | ||
} | ||
return nums[index] + rob_recursion(nums, index + 2) | ||
} | ||
} | ||
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 @@ | ||
package leetcode_study | ||
|
||
class Solution { | ||
fun longestConsecutive(nums: IntArray): Int { | ||
nums.sort() | ||
val consecutiveArray = IntArray(nums.size) | ||
var maxCount = 0 | ||
for (i in nums.lastIndex - 1 downTo (0)) { | ||
if (nums[i] + 1 == nums[i + 1]) { | ||
consecutiveArray[i] += consecutiveArray[i + 1] + 1 | ||
if (consecutiveArray[i] > maxCount) { | ||
maxCount = consecutiveArray[i] | ||
} | ||
} | ||
} | ||
return maxCount + 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,15 @@ | ||
class Solution { | ||
fun topKFrequent(nums: IntArray, k: Int): IntArray { | ||
val answer = IntArray(k) | ||
val set = nums.toSet() | ||
val mutableList = mutableListOf<Pair<Int, Int>>() | ||
set.forEach { num -> | ||
mutableList.add(num to nums.count { it == num }) | ||
} | ||
mutableList.sortByDescending { it.second } | ||
for (i in 0 until k) { | ||
answer[i] = mutableList[i].first | ||
} | ||
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,12 @@ | ||
class Solution { | ||
fun isPalindrome(s: String): Boolean { | ||
val filterStr = s | ||
.lowercase() | ||
.filter { it in 'a'..'z' } | ||
if (filterStr.isEmpty()) return true | ||
for (i in 0..filterStr.lastIndex / 2) { | ||
if (filterStr[i] != filterStr[filterStr.lastIndex - i]) 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.