当前位置:   article > 正文

C++ | Leetcode C++题解之第275题H指数II

C++ | Leetcode C++题解之第275题H指数II

题目:

题解:

  1. class Solution {
  2. public:
  3. int hIndex(vector<int>& citations) {
  4. int n = citations.size();
  5. int left = 0, right = n - 1;
  6. while (left <= right) {
  7. int mid = left + (right - left) / 2;
  8. if (citations[mid] >= n - mid) {
  9. right = mid - 1;
  10. } else {
  11. left = mid + 1;
  12. }
  13. }
  14. return n - left;
  15. }
  16. };
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/890086
推荐阅读
相关标签
  

闽ICP备14008679号