Skip to content

Commit b5f83bd

Browse files
author
Partho Biswas
committed
no message
1 parent a783614 commit b5f83bd

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
2-
# # Recursive approach
1+
# Recursive Approach
32
# class Solution(object):
43
# def findPeakElement(self, nums):
54
# """
65
# :type nums: List[int]
76
# :rtype: int
87
# """
98
# return self.findPeakElementHelper(nums, 0, len(nums) - 1)
10-
#
9+
1110
# def findPeakElementHelper(self, nums, left, right):
1211
# if left == right:
1312
# return left
@@ -17,7 +16,8 @@
1716
# else:
1817
# return self.findPeakElementHelper(nums, mid + 1, right)
1918

20-
# Iterative solution
19+
20+
# Time: O(log n) uses Binary search
2121
class Solution(object):
2222
def findPeakElement(self, nums):
2323
"""
@@ -28,8 +28,24 @@ def findPeakElement(self, nums):
2828
while left < right:
2929
mid = (left + right) // 2
3030
if nums[mid] > nums[mid + 1]:
31-
right = mid
31+
right = mid
3232
else:
3333
left = mid + 1
3434
return left
3535

36+
37+
# Solution. during Mock test
38+
# Time: O(n) uses Linear search
39+
class Solution(object):
40+
def findPeakElement(self, nums):
41+
"""
42+
:type nums: List[int]
43+
:rtype: int
44+
"""
45+
peak = 0
46+
if len(nums) <= 0:
47+
return peak
48+
for i in range(1, len(nums)):
49+
if nums[i] > nums[peak]:
50+
peak = i
51+
return peak

leetcode.com/python/459_Repeated_Substring_Pattern.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,26 @@ def repeatedSubstringPattern(self, s):
99
ss = s + s
1010
ss = ss[1:-1]
1111
return ss.find(s) != -1
12+
13+
14+
15+
# My solution duting Mock contest
16+
from collections import Counter
17+
class Solution(object):
18+
def repeatedSubstringPattern(self, s):
19+
"""
20+
:type s: str
21+
:rtype: bool
22+
"""
23+
if len(s) < 0:
24+
return False
25+
L = len(s)
26+
for i in range(L // 2):
27+
if L % (i + 1) == 0:
28+
pieces = []
29+
for j in range(0, L, i + 1):
30+
pieces.append(s[j:j + i + 1])
31+
counter = Counter(pieces)
32+
if len(counter) == 1:
33+
return True
34+
return False

0 commit comments

Comments
 (0)