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
6 changes: 6 additions & 0 deletions contains-duplicate/yhkee0404.kt
Copy link
Contributor

Choose a reason for hiding this comment

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

간결한 풀이로 보입니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution {
fun containsDuplicate(nums: IntArray): Boolean {
return nums.toSet()
.size != nums.size
}
}
11 changes: 11 additions & 0 deletions house-robber/yhkee0404.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
impl Solution {
pub fn rob(nums: Vec<i32>) -> i32 {
let mut dp = vec![0; nums.len() + 1];
dp[1] = nums[0];
for i in 2..dp.len() {
dp[i] = dp[i - 1].max(dp[i - 2] + nums[i - 1]);
}
return *dp.last()
.unwrap_or(&0)
}
}
22 changes: 22 additions & 0 deletions longest-consecutive-sequence/yhkee0404.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
func longestConsecutive(nums []int) int {
ans := 0
sort.Ints(nums)
i := 0
for i != len(nums) {
j := i + 1
k := 0
for j != len(nums) {
diff := nums[j] - nums[j - 1]
if diff > 1 {
break
}
j++
if diff == 0 {
k++
}
}
ans = max(ans, j - i - k)
i = j
}
return ans
}
11 changes: 11 additions & 0 deletions top-k-frequent-elements/yhkee0404.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object Solution {
def topKFrequent(nums: Array[Int], k: Int): Array[Int] = {
return nums.groupBy(identity)
.view.mapValues(_.size)
.toSeq
.sortBy(- _._2)
.take(k)
.map(_._1)
.toArray
}
}
11 changes: 11 additions & 0 deletions two-sum/yhkee0404.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
func twoSum(nums []int, target int) []int {
indices := make(map[int]int)
for i, num := range nums {
j, ok := indices[target - num]
if ok {
return []int{j, i}
}
indices[num] = i
}
return []int{}
}