Skip to content

Commit 4961df9

Browse files
authored
Create count-number-of-teams.py
1 parent f0ff2b2 commit 4961df9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Python/count-number-of-teams.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n^2)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def numTeams(self, rating):
6+
"""
7+
:type rating: List[int]
8+
:rtype: int
9+
"""
10+
result = 0
11+
for i in xrange(1, len(rating)-1):
12+
less, greater = [0]*2, [0]*2
13+
for j in xrange(len(rating)):
14+
if rating[i] > rating[j]:
15+
less[i < j] += 1
16+
if rating[i] < rating[j]:
17+
greater[i < j] += 1
18+
result += less[0]*greater[1] + greater[0]*less[1]
19+
return result

0 commit comments

Comments
 (0)