# 64、滑动窗口的最大值

# -*- coding:utf-8 -*-
class Solution:
def maxInWindows(self, num, size):
# write code here
if size>len(num):
return []
if size == 0:
return []
res = []
count = 0
# 队列
queue = num[:size]
res.append(max(queue))
while size+count < len(num):
queue.pop(0)
queue.append(num[size+count])
count+=1
res.append(max(queue))
return res


# 32、把数组排成最小的数

# -*- coding:utf-8 -*-
class Solution:
def PrintMinNumber(self, numbers):
# write code here
n = len(numbers)
for i in range(n):
for j in range(i+1, n):
if int(str(numbers[i])+str(numbers[j])) > int(str(numbers[j])+str(numbers[i])):
numbers[j],numbers[i] = numbers[i],numbers[j]
return ''.join([str(i) for i in numbers])


# 35、数组中的逆序对

# -*- coding:utf-8 -*-
class Solution:
def InversePairs(self, data):
# write code here
# 第一反应是冒泡排序swap次数即逆序对个数，但复杂度高
# 所以使用归并排序，比较时计算逆序对个数
self.count = 0

def merge_sort(lists):
if len(lists) <= 1:
return lists
mid = len(lists) // 2
left = merge_sort(lists[:mid])
right = merge_sort(lists[mid:])
return merge(left, right)

def merge(nums1, nums2):
res = []
i = 0
j = 0
while i < len(nums1) and j < len(nums2):
if nums1[i] <= nums2[j]:
res.append(nums1[i])
i += 1
else:
res.append(nums2[j])
j += 1
self.count += len(nums1) - i  # 这里是最重要的一处
res += nums1[i:]
res += nums2[j:]
return res

merge_sort(data)
return self.count%1000000007


# 40、数组中只出现一次的数字

# -*- coding:utf-8 -*-
class Solution:
# 返回[a,b] 其中ab是出现一次的两个数字
def FindNumsAppearOnce(self, array):
# write code here
num = []
for i in range(len(array)):
if array.count(array[i]) == 1:
num.append(array[i])
return num

10-04 411
04-17 2564

07-20 899
06-29 444
07-16 633
11-15 713