You are viewing a single comment's thread. Return to all comments →
complexity of count function is O(n),so your code complexity will become O(n^2)
#include <bits/stdc++.h> using namespace std; int dosome(int arr[], int n) { if(n==1) return 1; sort(arr,arr+n); for(auto i=0;i<n;) { if(arr[i]==arr[i+1]) i=i+2; else return arr[i]; } // return arr[n-1]; return 0; } int main() { int n; cin>>n; int arr[n]; for(auto j=0;j<n;j++) cin>>arr[j]; cout << dosome(arr, n) << endl; }
sorting required O(nlogn) complexity ,my Code Complexity will be O(nlogn+n)==O(nlogn)
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
complexity of count function is O(n),so your code complexity will become O(n^2)
sorting required O(nlogn) complexity ,my Code Complexity will be O(nlogn+n)==O(nlogn)