1
0

Q274.h 621 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Created by 李洋 on 2023/10/29.
  3. //
  4. #ifndef LEECODE_C_Q274_H
  5. #define LEECODE_C_Q274_H
  6. #include <vector>
  7. using namespace std;
  8. class Q274 {
  9. public:
  10. int hIndex(vector<int> &citations) {
  11. sort(citations.begin(), citations.end(), [](int a, int b) {
  12. return a > b;
  13. });
  14. for (int i = 1; i < citations.size(); ++i) {
  15. if (citations[i - 1] < i) {
  16. return i - 1;
  17. }
  18. if (i + 1 == citations.size() - 1) {
  19. return i + 1;
  20. }
  21. }
  22. return citations[0] == 0 ? 0 : 1;
  23. }
  24. };
  25. #endif //LEECODE_C_Q274_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。