Answers for "mark occurances of elements in array cpp"

2

mark occurances of elements in array cpp

int sumOfDistinct(int a[], int n){
  	int sum = 0; 
    for (int i = 0; i < n; i++) { 
      	 // If element appears first time 
        if (a[abs(a[i]) - 1] >= 0) { 
            sum += abs(a[i]); 
            a[abs(a[i]) - 1] *= -1; 
        } 
    } 
    return sum;
Posted by: Guest on May-02-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language