Advertisement
jibha

Untitled

Feb 8th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class Solution {
  2. public:
  3.  
  4. vector<int> b_s(vector<vector<int>>& mat,int left,int right){
  5.  
  6. auto l=mat[left];
  7. auto r=mat[right];
  8.  
  9. int mid=left+right;
  10. mid/=2;
  11. auto m=mat[mid];
  12.  
  13. auto m_max=max_element(m.begin(),m.end());
  14. auto l_max=max_element(l.begin(),l.end());
  15. auto r_max=max_element(r.begin(),r.end());
  16.  
  17. while(left<right){
  18.  
  19. if(*m_max>*l_max){
  20. return b_s(mat,left,mid);
  21. }else{
  22. return b_s(mat,mid+1,right);
  23. }
  24.  
  25. }
  26.  
  27. return {mid,(int)(m_max-m.begin())};
  28.  
  29. }
  30.  
  31. vector<int> findPeakGrid(vector<vector<int>>& mat) {
  32.  
  33. return b_s(mat,0,(int)mat.size()-1);
  34.  
  35. }
  36. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement