Python笔试题:给定一个整数数组和一个目标值、找出数组中为2个俩个数、若无返回-1【杭州多测师】【杭州多测师_王sir】

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | class Test: def func( self ): ''' 给定一个整数数组和一个目标值、找出数组中为2个俩个数、若无返回-1 :return: ''' list1 = [ - 1 , - 2 , 4 , 3 , 1 , 0 , 2 ] # list1 = [-1,4,5] new = [] for i in range ( len (list1)): for j in range ( len (list1) - i - 1 ): if list1[i] + list1[j] = = 2 : new.append((list1[i],list1[j])) if new ! = []: print (new) else : print ( - 1 ) def reverse( self , x): a = 2 * * 31 - 1 #int32最大值是:2147483647 b = - ( 2 * * 31 ) #int32最小值是:-2147483648 n = 0 while x ! = 0 : m = - ( abs (x) % 10 ) if x < 0 else x % 10 x = int (x / 10 ) if n > int (a / 10 ) or n = = int (a / 10 ) and m > 7 : # int32最大值是2147483647,最后一位是7 return 0 if n < int (b / 10 ) or n = = int (b / 10 ) and m < - 8 : # int32最小值是-2147483648,最后一位是8 return 0 n = n * 10 + m return n t = Test() t.func() #第一个题目 print (t.reverse( 341 )) #第二个题目 |
分类:
多测师_Python
标签:
python
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
2021-08-18 把字符串当中重复的字符打印出来【杭州多测师】【杭州多测师_王sir】