俺写的代码如下:
nums = eval(input())
l = eval(input())
r = eval(input())
class Solution:
def checkArithmeticSubarrays(self, nums, l, r):
none_list = []
m = 0
for i in range(0, len(l)):
new_nums = nums[l[i]:r[i]+1]
new_nums.sort()
new = new_nums
n = -2
for j in range(0, len(new)):
n += 1
res = new[1+n] - new[n]
if new[j] == new[0] + (j) * res:
if j == len(new)-1:
none_list.append('%s' % 'ture')
else:
if j == len(new)-1:
none_list.append('%s' % 'false')
for k in none_list:
m += 1
if m == len(none_list):
print(k, end=']')
elif 1 < m < len(none_list):
print(k, end=',')
else:
print(f'[{k}', end=',')
x = Solution()
x.checkArithmeticSubarrays(nums, l, r)
题目如下:
你不认真审题啊
看好输入格式了吗
exec(input().replace(',',';'))
nums=locals()['nums']
l =locals()['l']
r = locals()['r']
不知道你这个问题是否已经解决, 如果还没有解决的话:tips:
注意图中:
索引-1: 表示取最后一个元素
(2)代码