LintCode第23题:判断数字与字母字符
描述:给出一个字符c,如果它是一个数字或字母,返回true,否则返回false。
解题思路:
这道题我们直接通过ascii码进行判断即可
代码如下:
class Solution:
"""
@param c: A character.
@return: The character is alphanumeric or not.
"""
def is_alphanumeric(self, c):
# write your code here
if (ord(c)>=97 and ord(c)<=122) or (ord(c)>=65 and ord(c)<=90) or (ord(c)>=48 and ord(c)<=57):
return True
else:
return False
该篇博客介绍了如何通过ASCII码来判断一个字符是否为字母或数字。提供的解决方案是创建一个名为`is_alphanumeric`的方法,通过比较字符的ASCII值范围来确定其是否在字母或数字的范围内,从而返回相应的布尔结果。
3万+

被折叠的 条评论
为什么被折叠?



