Back to course home
0% completed
Vote For New Content
Getting error ./UserCode.go:2:1: syntax error: non-declaration statement outside function body and same code is working in go playground
Shraddha
May 8, 2024
package main
import "fmt"
// containsDuplicate checks for duplicates in a slice of integers
func containsDuplicate(nums []int) bool {
if len(nums) == 0 || nums == nil {
return false
}
for i := 0; i< len(nums) - 1; i++ {
for j := i+1 ; j < len(nums) ; j++ {
if nums[i] == nums[j] {
return true
}
}
}
// ToDo: Write Your Code Here.
return false
}
func main() {
arr := [][]int{
{1,2,3,4},
{1,2,3,1},
}
for _, input := range arr {
isDuplicate := containsDuplicate(input)
fmt.Println(isDuplicate)
}
}
0
0
Comments
Comments
Shubham Voraa year ago
Dear Shraddha,
Just try to submit the code of containsDuplicate method as shown below. You always need to remove main() functions and package main,import "fmt" from the code before submitting.
// Solution struct type type Solution struct{} ...
On this page
Problem Statement
Examples
Try it yourself