111
由bqv4zl7q创建,最终由bqv4zl7q 被浏览 2 用户
102
# 在有序数组中找到出现最多的元素
def func() :
num = arr[0]
cnt = arr1
maxNum = arr[0]
maxCnt = 1
for i in arr[1:]:
if i == num :
cnt += 1
else:
if cnt > maxCnt:
maxCnt = cnt
maxNum = num
if cnt > maxCnt:
maxCnt = cnt
maxNum = num
return maxNum
\
103
def func(a) :
new_arr = [arr[0]]
for i in arr[1:]:
if i != new_arr[-1]:
new_arr.append(num)
return new_arr
\
104
def func(arr, target):
left, right = 0, len(arr) - 1
count = 0
while left < right:
sumVal = arr[left] + arr[right]
if sumVal == target:
count += 1
left += 1
right -= 1
elif sumVal < target:
left += 1
else :
right -= 1
return count
\