-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1.py
69 lines (64 loc) · 1.97 KB
/
p1.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
# @Date : 2019/4/2
# @Time : 0:02
# @Author : Daishijun
# @File : p1.py
# Software : PyCharm
class Solution:
# import copy
def InversePairs(self, data):
# write code here
if data == None:
return 0
# copydata = copy.deepcopy(data)
copydata = []
for d in data:
copydata.append(d)
print(len(copydata))
def Core(data, cdata, start, end):
if start == end:
cdata[start] = data[start]
return 0
length = (end - start) >> 1
left = Core(cdata, data, start, start + length)
right = Core(cdata, data, start + length + 1, end)
leftp = start + length
rightp = end
indexc = end
count = 0
while leftp >= start and rightp >= start + length + 1:
if data[leftp] > data[rightp]:
cdata[indexc] = data[leftp]
indexc -= 1
leftp -= 1
count += rightp - start - length
else:
cdata[indexc] = data[rightp]
indexc -= 1
rightp -= 1
while leftp >= start:
cdata[indexc] = data[leftp]
indexc -= 1
leftp -= 1
while rightp >= start + length + 1:
cdata[indexc] = data[rightp]
indexc -= 1
rightp -= 1
print('data:', data,'\n','copy:',cdata)
print('count:',count + left + right )
return count + left + right
recount = Core(data, copydata, 0, len(data) - 1)
return recount % 1000000007
if __name__ == '__main__':
# s = Solution()
# ls = [7,5,6,4]
# print(s.InversePairs(ls))
#
a = '1'
b = '3'
li = list(range(258))
# print(li[a])
print(ord(a))
print(type(ord(a)))
print(chr(49))
print(type(chr(49)))