题解 | #牛牛的特殊数字#
牛牛的特殊数字
https://www.nowcoder.com/practice/2f195566eb5442e883c371d8cfee8c77
from re import T # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param num int整型 # @return bool布尔型 # class Solution: def isSpecialNumber(self , num: int) -> bool: num = list(map(int, list(str(num)))) flag = 0 left = 0 right = len(num)-1 while left < right-1: # print(num) if num[left] != num[right]: if num[left] == 1: # x2 = [1, num[right]] num[right-1] -= 1 num[left+1] -= num[right] if num[right-1]<0 or num[left+1]<0: flag = 1 break else: num[left] -= num[right] if num[left] != 1: flag = 1 break left += 1 right -= 1 if flag==0 and (left == right or num[right]%2==0): return True else: return False