We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aef8ed1 commit fd532f3Copy full SHA for fd532f3
Python/largest-3-same-digit-number-in-string.py
@@ -0,0 +1,32 @@
1
+# Time: O(n)
2
+# Space: O(1)
3
+
4
+# string
5
+class Solution(object):
6
+ def largestGoodInteger(self, num):
7
+ """
8
+ :type num: str
9
+ :rtype: str
10
11
+ result = ""
12
+ cnt = 0
13
+ for i, x in enumerate(num):
14
+ cnt += 1
15
+ if i+1 < len(num) and num[i] == num[i+1]:
16
+ continue
17
+ if cnt >= 3:
18
+ result = max(result, num[i])
19
20
+ return result*3
21
22
23
24
25
26
+class Solution2(object):
27
28
29
30
31
32
+ return max(num[i] if num[i] == num[i+1] == num[i+2] else "" for i in xrange(len(num)-2))*3
0 commit comments