1
0

520.c 864 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // Created by 李洋 on 2024/6/23.
  3. //
  4. #ifndef LEETCODE_C_520_CPP
  5. #define LEETCODE_C_520_CPP
  6. #include <stdlib.h>
  7. #include "ctype.h"
  8. #include "stdbool.h"
  9. #include "string.h"
  10. char *toLowerCase(const char *str) {
  11. char *result = (char *) malloc(sizeof(char) * strlen(str));
  12. for (int i = 0; i < strlen(str); i++) {
  13. result[i]= tolower(str[i]);
  14. }
  15. return result;
  16. }
  17. // 通过数值判断
  18. bool detectCapitalUse(char *word) {
  19. char *lower = toLowerCase(word);
  20. int count = 0;
  21. for (int i = 0; i < strlen(word); ++i) {
  22. count += lower[i] - word[i];
  23. }
  24. int interval = 'a' - 'A';
  25. if ((count == interval && word[0] >= 'A' && word[0] <= 'Z') || count == interval * strlen(word) || count == 0) {
  26. return true;
  27. }
  28. return false;
  29. }
  30. bool run() {
  31. return detectCapitalUse("USA");
  32. }
  33. #endif //LEETCODE_C_520_CPP
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。