logo

不用迭代方法,写程序判断字符串是否为回文。

Write a Python program to check whether a given string is a palindrome or not, without using an iterative method.

题目类型: 技术面试题

这是一道技术面试题,常见于澳洲IT公司面试中。

难度: medium

分类: algorithms

标签: python, palindrome, recursion

参考答案摘要

TL;DR 可以用递归或切片直接判断 s == s[::-1] 。 切片法 def is_pal(s): s = ''.join(c.lower() for c in s if c.isalnum()) return s == s[::-1] 递归法 def is_pal_rec(s): s = ''.join(c.lower() for c in s if c.isalnum()) if len...

本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。

← 返回面试题库

不用迭代方法,写程序判断字符串是否为回文。

Mediumpythonalgorithms

想查看完整答案?

登录匠人学院学习中心,获取 STAR 格式回答和详细技术解析

前往学习中心查看答案