Skip to content

Commit 2bd169d

Browse files
committed
2019-08-13
1 parent b084b0f commit 2bd169d

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

0237.删除链表中的节点/0237-删除链表中的节点.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ def deleteNode(self, node):
1111
:rtype: void Do not return anything, modify node in-place instead.
1212
"""
1313
node.val = node.next.val
14-
node.next = node.next.next
14+
node.next = node.next.next
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution(object):
2+
def isMajorityElement(self, nums, target):
3+
"""
4+
:type nums: List[int]
5+
:type target: int
6+
:rtype: bool
7+
"""
8+
return nums.count(target) > len(nums) // 2
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Solution(object):
2+
def mostVisitedPattern(self, username, timestamp, website):
3+
"""
4+
:type username: List[str]
5+
:type timestamp: List[int]
6+
:type website: List[str]
7+
:rtype: List[str]
8+
"""
9+
from collections import defaultdict
10+
record = defaultdict(list)
11+
for i, un in enumerate(username):
12+
record[un].append([timestamp[i], website[i]])
13+
# print record
14+
row = defaultdict(int)
15+
for key in record.keys():
16+
record[key].sort()
17+
# print record[key]
18+
used = set()
19+
for i in range(len(record[key])):
20+
for j in range(i + 1, len(record[key])):
21+
for k in range(j + 1, len(record[key])):
22+
sequence = record[key][i][1] + "+" + record[key][j][1]+ "+" + record[key][k][1]
23+
if sequence not in used:
24+
row[sequence] += 1
25+
used.add(sequence)
26+
# print row
27+
possible_sol = []
28+
max_freq = max(row.values())
29+
for key, val in row.items():
30+
if val == max_freq:
31+
possible_sol.append(key.split("+"))
32+
possible_sol = possible_sol[::-1]
33+
# print possible_sol
34+
if len(possible_sol) > 1:
35+
possible_sol.sort()
36+
return possible_sol[0]

0 commit comments

Comments
 (0)