update on more problem solving

swadhinbiswas committed 1 years ago
3fc0eac
1 parent f98225a
commit 3fc0eac
6 files changed
+87 -1
▼852. Peak Index in a Mountain Array.py
+16-0
1
+class Solution:
2
+ def peakIndexInMountainArray(self, arr: List[int]) -> int:
3
+ start=1;end=len(arr)-2
4
+ while(start<=end):
5
+ mid=start+(end-start)//2
6
+ if arr[mid-1]<arr[mid] and arr[mid]>arr[mid+1]:
7
+ return mid
8
+ elif arr[mid-1]<arr[mid]:
9
+ start=mid+1
10
+ else:
11
+ end=mid-1
12
+ return -1
13
+
14
+
15
+
16
+
0
17
▼Regular Expression Matching.py
+1-1
1
1
class Solution:
2
2
def isMatch(self, s: str, p: str) -> bool:
3
-
3
+ pass
4
4
5
5
6
6
▼Toph.co/540. Single Element in a Sorted Array.py
+30-0
1
+from typing import List
2
+
3
+class Solution:
4
+ def singleNonDuplicate(self, nums: List[int]) -> int:
5
+ start=0;end=len(nums)-1
6
+ n=len(nums)
7
+ if (n==1):
8
+ return nums[0]
9
+ while(start<=end):
10
+ mid=start+(end-start)//2
11
+
12
+ if (mid > 0 and nums[mid - 1] != nums[mid]) and (mid < n - 1 and nums[mid + 1] != nums[mid]):
13
+ return nums[mid]
14
+ if (mid%2)==0:
15
+ if nums[mid-1]!=nums[mid]:
16
+ start=mid+1
17
+
18
+ else:
19
+ end=mid-1
20
+ else:
21
+ if nums[mid-1]!=nums[mid]:
22
+ end=mid-1
23
+ else:
24
+ start=mid+1
25
+
26
+
27
+
28
+
29
+x=Solution().singleNonDuplicate([3,3,7,7,10,11,11])
30
+print(x)
0
31
▼Toph.co/An Obvious Interactive Problem.py
+19-0
1
+class Solve:
2
+ def binarysearch():
3
+ start=0;end=10**6
4
+ while(start<=end):
5
+ mid=start+(end-start)//2
6
+ print(mid)
7
+ x=str(input()).lower()
8
+ if x=="bigger":
9
+ start=mid+1
10
+ elif x=="smaller":
11
+ end=mid-1
12
+ elif x=="bingo":
13
+ break
14
+ else:
15
+ break
16
+
17
+
18
+
19
+Solve.binarysearch()
0
20
▼Toph.co/Easy Sequence 1.py
+3-0
1
+for _ in range(int(input())):
2
+ x=int(input())
3
+ print(f"Case {_+1}: {_+1} ")
0
4
▼Toph.co/test.ipynb
+18-0
357
357
" for j in range(i, 0, -1):\n",
358
358
" print(j, end=\"\")"
359
359
]
360
+ },
361
+ {
362
+ "cell_type": "code",
363
+ "execution_count": 1,
364
+ "metadata": {},
365
+ "outputs": [
366
+ {
367
+ "name": "stdout",
368
+ "output_type": "stream",
369
+ "text": [
370
+ "1\n"
371
+ ]
372
+ }
373
+ ],
374
+ "source": [
375
+ "n=[1]\n",
376
+ "print(len(n))"
377
+ ]
360
378
}
361
379
],
362
380
"metadata": {
363
381