题解 |判断回文串

判断回文

http://www.nowcoder.com/practice/e297fdd8e9f543059b0b5f05f3a7f3b2

双指针

import java.util.*; 
public class Solution {
    public boolean judge (String str) {
        // write code here
        int left = 0, right = str.length() - 1;
        while (left < right){
            if (str.charAt(left) != str.charAt(right)){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务