Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a256d29

Browse files
Merge pull request #340 from MoigeMatino/add-longest-streak-v4
feat: add longest streak v4
2 parents 8ae54f2 + e75ee09 commit a256d29

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def longest_streak(head):
2+
if head is None:
3+
return 0
4+
5+
if head.next is None:
6+
return 1
7+
8+
comparison_val = head.val
9+
curr_streak = 1
10+
max_streak = 0
11+
current = head.next
12+
while current:
13+
if current.val == comparison_val:
14+
curr_streak += 1
15+
else:
16+
if curr_streak > max_streak:
17+
max_streak = curr_streak
18+
comparison_val = current.val
19+
curr_streak = 1
20+
21+
current = current.next
22+
return max_streak

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /