this solution should work, however, the problem is failing in input [2,2,2,2,2] .
this is not a valid input as this has more than 1 duplicate.
this input can be removed from the problem
'''class Solution {
public int findDuplicate(int[] nums) {
int n= nums.length -1;
int finalsum=(n)* (n+1)/2;
int sum=0;
for(int i=0;i<nums.length;i++){
sum+=nums[i];
}
return sum-finalsum;
}}'''