You are viewing a single comment's thread. Return to all comments →
one of cpp solution
int findMin(vector<int> arr){ int min=INT8_MAX; for(int i=0;i<arr.size();i++){ if(min>arr[i]){ min=arr[i]; } } return min; } void subfunc(vector<int>& arr,int sub){ vector<int>::iterator itr=arr.begin(); for(int i=0;i<arr.size();i++){ arr[i]-=sub; } } void cutTheSticksHelper(vector<int>& arr){ vector<int>::iterator itr=arr.begin(); int min=findMin(arr); subfunc(arr,min); itr=arr.begin(); while(itr!=arr.end()){ if(*itr<=0){ arr.erase(itr); }else{ ++itr; } } } vector<int> cutTheSticks(vector<int> arr) { vector<int> ans; vector<int>::iterator itr=arr.begin(); // ans.push_back(arr.size()); do{ ans.push_back(arr.size()); cutTheSticksHelper(arr); }while (arr.size()>0); return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cut the sticks
You are viewing a single comment's thread. Return to all comments →
one of cpp solution