Incompatible types: int[] cannot be converted to List<Integer>


  • 7
    R

    I don't get why I got this error while I never used an array in my answer.

    I think they edited the question, because the beginning of the solution is "public int findPeakElement(List nums) {" and in the answers, I saw people using an array of int.

    I tried using an array it doesn't work either.


  • 1
    D

    It fails for me too. Based on the fact that it fails on the last line after my code, I'd assume there is some issue with whatever is executing it.


  • 2
    W

    I changed the predefined input parameters to int[] nums, and it starts working. I think they change the question but did not change the test case.


  • 0
    M

    I got exactly the same result


  • -4

    Yes, the default code signature is modified to accept int[] instead of List<Integer>. Please click on the "reload" button above the code editor to reload the default code.


  • 0
    R

    The default code is still with "List<Integer>", while it works with int[]. I think you need to modify it.


  • 0
    N

    Changing the signature to

    public int findPeakElement(int[] nums)
    

    works.


  • 0
    D

    Thanks for your answers. I changed the List to int and solved it.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.