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
7 changes: 7 additions & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ fun main() {
node3.next = node1 // cycle back to x
val llcdResult = linkedListCycleDetection.hasCycle(node1)
println("Has cycle $llcdResult")

// Calling Contains Duplicate
val `containsDuplicate.kt` = `ContainsDuplicate.kt`()
val containsDuplicateResult = `containsDuplicate.kt`
.containsDuplicate(intArrayOf(1,2,3,1,0,1))
println("Contains Duplicate Integers $containsDuplicateResult")

}
27 changes: 27 additions & 0 deletions src/main/kotlin/dsalgoleetcode/ContainsDuplicate.kt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main.kotlin.dsalgoleetcode

/**
* Contains Duplicate
* Given an integer array nums, return true if any value appears at least twice in the
* array, and return false if every element is distinct.
*
* Example 1:
* Input: nums = [1,2,3,1]
* Output: true
* Explanation:
* The element 1 occurs at the indices 0 and 3.
* */

class `ContainsDuplicate.kt` {

fun containsDuplicate(nums: IntArray): Boolean {

val seen = mutableSetOf<Int>()
for(i in nums){
if( i in seen)
return true
seen.add(i)
}
return false
}
}