find duplicate in array

    0

    0

    The code in the example defines a function called findduplicate. The function takes a list of integers as input and prints out the list's duplicates. This function has two parameters: a list of integers and an optional boolean parameter that tells the function whether to print out the list's duplicates or not.

    The function def findduplicate takes a list of integers and prints out the list's duplicates. The function first prints out the list's length and then prints out the list's duplicates. The function prints out the list's duplicates by printing out the list's elements along with the index of the element that corresponds to the duplicated element.

    object solution extends App {
    println("hello world")
      //debugging(List(1,3,5,6,6,3,1))
      println(findduplicate(List(1,3,5,6,4,3,1)))
    
      def findduplicate(a:List[Int]): Int = {
        for (i <- 0 to a.length - 1) {
          for(j<- 1 to i){
            if (a(i)== a(j)) return a(i)
          }
        }
        return -1
      }
    /*
      def debugging(b:List[Int]): Unit = {
        for(i<- 0 to b.length-1) println(b(i) +" " +i)
      }
      */
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.