当前位置:网站首页>Leetcode skimming 03
Leetcode skimming 03
2022-07-22 01:10:00 【88 year old programming with injury】
leetcode Brush problem
Longest text substring ( secondary )
def longestPalindrome(self, s): # There are two situations , One is an odd number of palindromes , Another kind # Is an even number of palindromes
res = ''
for i in range(len(s)): # Traverse the entire array ,i For the pointer
start = max(i - len(res) -1, 0)
t = s[start: i+1]
if t == t[::-1]:
res = t
else:
t = t[1:]
if t == t[::-1]: # According to the index range of the selected palindrome substring , Slice the string
res = t
return res
Integer inversion ( secondary )
def reverse(self, x):
# Convert integers to character types for inversion
x = str(x)
res = ''
# If it is not a negative number, it will be reversed directly , Don't consider that the first one becomes 0, Because the character data needs to be converted into int data
if x[0] != '-':
res = x[::-1]
# If it's a negative number , Put the first position into '-', Remove the last bit after reversing
else:
res = '-' + x[::-1][0:-1]
max, min = 1, 1
for i in range(31):
max *= 2
min = -max
if int(res) >= min - 1 and int(res) <= max:
return int(res)
else:
return 0
边栏推荐
- 子网掩码的作用
- Low code tool revolution on the cusp of the storm
- Integer bisection, floating-point bisection and bisection function (lower_bound(), upper) in STL_ bound())
- Design and implementation of tcp/ip protocol stack LwIP: Part VII
- [ntp/chrony] how to use Chrony to configure NTP services
- Lens calibration board
- 【数据分析01】
- What platform can accommodate knowledge base, indicator base and rule base at the same time?
- 2022蓝桥杯省赛b组补题[九进制转十进制],[顺子日期],[刷题统计],[ 修剪灌木]
- 镜头标定板秩事
猜你喜欢
随机推荐
【数据分析02】
Attack and Defense Technology Part I - know the enemy (attack means)
Precautions for visual studio to reference external libraries
通过例子学C标准库<ctype.h>
Typescript (II)
ITK median filter
【HCIP持续更新】DHCP安全威胁
Live broadcast preview on July 13: Ark low code platform live broadcast is coming
银行合规程序KYC、CDD、AML和TM
Interpreting the maker education model in line with the mainstream of the new era
Automatic reference counting and circular reference
Comprehensive experiment of mGRE and OSPF
Steve Aoki 的人物化身将来到 The Sandbox 元宇宙!
【RM_EE_Note】2 串口&遥控器
20220719 adapt openharmony-v3.1-beta to aio-3568j
CUDA文件中无法打开源文件<stdio.h>
解读符合新时代主流的创客教育模式
Conversion module of three-phase differential encoder into pulse signal or open collector
Openshift 4 - install ODF and deploy red hat Quay (3 worker)
What is the new generation of enterprise IT architecture? Cloud primordial? Low code?