Compile error for JAVA


  • 0
    B

    I wrote my code as follows for this problem:

    public class Solution {
    public int singleNumber(int[] A, int n) {
    int result = A[0];
    for (int i = 0; i < n; i++) {
    result ^= A[i];
    }
    return result;
    }
    }

    After submitting, it showed
    Line 20: error: method singleNumber in class Solution cannot be applied to given types;

    I have no idea about the error.


  • 0
    P

    You changed function definition.

    It should be

     public int singleNumber(int[] A)
    

    instead of

    public int singleNumber(int[] A, int n)
    

    Make sure you select JAVA for your code. It looks like you chose C++.


  • 0
    Y

    For Java code, the method parameter only have int[] A. You should remove int n and use A.length instead of n in your code.


Log in to reply
 

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