symmetry.h 637 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Created by 李洋 on 2023/10/4.
  3. //
  4. #ifndef LEECODE_C_SYMMETRY_H
  5. #define LEECODE_C_SYMMETRY_H
  6. #include <string>
  7. #include <stack>
  8. bool isSymmetry(std::string target) {
  9. std::stack<char> tk;
  10. for (int i = 0; i < target.length(); ++i) {
  11. if (i < target.length() / 2) {
  12. tk.push(target[i]);
  13. }
  14. if (i == target.length() / 2 && target.length() % 2 == 1) {
  15. i++;
  16. }
  17. if (i >= target.length() / 2) {
  18. if (target[i] != tk.top()) {
  19. return false;
  20. }
  21. tk.pop();
  22. }
  23. }
  24. return true;
  25. }
  26. #endif //LEECODE_C_SYMMETRY_H
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。