目录

009. 回文数

125. 验证回文串


009. 回文数

【题目】:

LeetCode-回文数-9、125

【代码】:

方法1:

LeetCode-回文数-9、125

方法2:

LeetCode-回文数-9、125

方法3:

LeetCode-回文数-9、125


125. 验证回文串

【题目】:

LeetCode-回文数-9、125

【代码】:

class Solution {
    public boolean isPalindrome(String s) {
       int len = s.length();
		int i = 0, j = len - 1;
		while (i < j) {
			char a = s.charAt(i);
			char b = s.charAt(j);
			if (!isvalid(a)) {
				i++;
				continue;
			}
			if (!isvalid(b)) {
				j--;
				continue;
			}

			if(a<'A'||b<'A') { //数字
				if(a==b) {
					i++;
					j--;
				}else {
					return false;
				}
			}else if (Math.abs(a - b) == 32 || (a - b) == 0) { //字母
				i++;
				j--;
			}else {
				return false;
			}

		}
		//System.out.println(j);
		return true;
    }
    
    public static boolean isvalid(char c) {
		if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
			return true;
		}else {
			return false;
		}
    }
      
}

 

相关文章:

  • 2021-01-29
  • 2022-01-13
  • 2021-10-18
  • 2021-04-17
  • 2021-07-28
  • 2021-12-19
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2022-01-10
  • 2021-07-13
  • 2021-05-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案