more problem

swadhinbiswas committed 1 years ago
34f7472
1 parent 6cdab40
commit 34f7472
6 files changed
+139 -0
▼11. Container With Most Water.py
+49-0
1
+
2
+from typing import List
3
+
4
+class Solution:
5
+ def maxArea(self, height: List[int]) -> int:
6
+ leftpointer=0
7
+ rightpointer=len(height)-1
8
+ maxarea=0
9
+ while leftpointer<rightpointer:
10
+ h=min(height[leftpointer],height[rightpointer])
11
+ width=rightpointer-leftpointer
12
+ area=width*h
13
+ maxarea=max(area,maxarea)
14
+ if height[leftpointer]<height[rightpointer]:
15
+ leftpointer+=1
16
+ else:
17
+ rightpointer-=1
18
+
19
+ return maxarea
20
+
21
+
22
+print(Solution().maxArea([1,8,6,2,5,4,8,3,7]))
23
+
24
+
25
+
26
+class Solution:
27
+ def maxArea(self, height: List[int]) -> int:
28
+ left,maxarea,right=0,0,len(height)-1
29
+ while left<right:
30
+ h=min(height[left],height[right])
31
+ width=right-left
32
+ area=h*width
33
+ maxarea=max(area,maxarea)
34
+ if height[left]<height[right]:
35
+ left+=1
36
+ else:
37
+ right-=1
38
+ return maxarea
39
+
40
+
41
+print(Solution().maxArea([1,8,6,2,5,4,8,3,7]))
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
0
50
▼136. Single Number.py
+19-0
9
9
10
10
11
11
12
+
13
+
14
+
15
+
16
+# For Toph compile
17
+
18
+test = int(input())
19
+numberlist = list(map(int, input().split()))[:test]
20
+
21
+def single_number(number):
22
+ answer = 0
23
+ for i in number:
24
+ answer ^= i
25
+
26
+ return answer
27
+
28
+x = single_number(numberlist)
29
+print(x)
30
+
12
31
▼26. Remove Duplicates from Sorted Array.py
+0-0
0
0
▼LeetcodeProblemsubmit1.py
+0-0
0
0
▼Product of Array Except Self - Leetcode 238 - Python.py
+41-0
1
+# from typing import List
2
+
3
+# class Solution:
4
+# def productExceptSelf(self, nums: List[int]) -> List[int]:
5
+# productofall=1
6
+# for i in range(len(nums)):
7
+# productofall*=nums[i]
8
+# for i in range(len(nums)):
9
+# x=nums[i]
10
+# if x!=0:
11
+# nums[i]=productofall//x
12
+# return nums
13
+# #Only For Positive Test Case
14
+
15
+
16
+from typing import List
17
+
18
+class Solution:
19
+ def productExceptSelf(self, nums: List[int]) -> List[int]:
20
+ n=len(nums)
21
+ array=[1]*n
22
+ prefix=1
23
+ for i in range(n):
24
+ array[i]=prefix
25
+ prefix*=nums[i]
26
+
27
+ suffix:int=1
28
+
29
+ for i in range(n-2,-1,-1):
30
+ suffix*=nums[i+1]
31
+ array[i]*=suffix
32
+
33
+ return array
34
+
35
+
36
+
37
+
38
+
39
+print(Solution().productExceptSelf([-1,1,0,-3,3]))
40
+
41
+
0
42
▼Toph.co/The Lost Digit.cpp
+30-0
1
+#include <iostream>
2
+#include <vector>
3
+#include <numeric> // For std::iota (optional, for alternative input)
4
+
5
+using namespace std;
6
+
7
+int single_number(const vector<int>& number) {
8
+ int answer = 0;
9
+ for (int i : number) { // Range-based for loop
10
+ answer ^= i;
11
+ }
12
+ return answer;
13
+}
14
+
15
+int main() {
16
+ int test;
17
+ cin >> test;
18
+
19
+ vector<int> numberlist(test); // Initialize vector with size 'test'
20
+
21
+ for (int i = 0; i < test; ++i) {
22
+ cin >> numberlist[i];
23
+ }
24
+
25
+
26
+ int x = single_number(numberlist);
27
+ cout << x << endl;
28
+
29
+ return 0;
30
+}
0
31