Its running fine in eclipse but its showing Runtime Error i.e :java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 (at line 14 i.e return a statement) can anyone help me with this


  • 0
    V

    public class Solution {
    public int singleNumber(int[] nums) {
    Arrays.sort(nums);
    ArrayList<Integer> q=new ArrayList<>();
    int io,li;
    int x;
    int a=0;
    for(int i=0;i<nums.length;i++)
    {
    q.add(nums[i]);
    }
    for(int i=0;i<nums.length;i++)
    {
    x=q.get(nums[i]);
    io=q.indexOf(x);
    li=q.lastIndexOf(x);
    if(io==li)
    {
    a=x;

            }
            
        }
        return a;
    }
    

    }


Log in to reply
 

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