Skip to content

Commit

Permalink
Contest 183 (py imp)
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Mar 31, 2020
1 parent c07d334 commit 7465ad4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 1394. Find Lucky Integer in an Array/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def findLucky(self, arr: List[int]) -> int:
d = {}
for x in arr:
d[x] = d.get(x, 0) + 1

max_res = -1
for k,v in d.items():
if k==v and max_res < k:
max_res = k
return max_res
2 changes: 2 additions & 0 deletions 1394. Find Lucky Integer in an Array/readme.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
可以直接调用 collections 模块
count = collections.Counter(arr)
14 changes: 14 additions & 0 deletions 1395. Count Number of Teams/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def numTeams(self, rating: List[int]) -> int:
res = 0
for n in (0, 1):
length = len(rating)
for i in range(0, length-2):
for j in range(i+1, length-1):
for k in range(j+1, length):
if n == 0 and rating[i] < rating[j] < rating[k]:
res+=1
elif n == 1 and rating[i] > rating[j] > rating[k]:
res+=1
return res

19 changes: 19 additions & 0 deletions 1395. Count Number of Teams/readme.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* Solution
** 三重循环 O(n^3)
** 二分
#+BEGIN_SRC python
class Solution:
def numTeams(self, rating: List[int]) -> int:
res = 0
for rating2 in [rating, rating[::-1]]:
d = []
d2 = []
for val in rating2:
ind = bisect.bisect_right(d, val)
d.insert(ind, val)
d2.insert(ind, ind)
res += sum(d2[:ind])

return res
#+END_SRC
** DP

0 comments on commit 7465ad4

Please sign in to comment.