date[24.01.2025]
swadhinbiswas committed 1 years ago
1428e25
1 parent 0b222ff
commit 1428e25
3 files changed
+41 -0
Showing 3 changed files+41-0
▼136. Single Number.py
+11-0
| @@ -0,0 +1,11 @@ | ||
1 | + | |
2 | +class Solution(object): | |
3 | + def singleNumber(self, number): | |
4 | + answer = 0 | |
5 | + for i in number: | |
6 | + answer=answer^i | |
7 | + | |
8 | + return answer | |
9 | + | |
10 | + | |
11 | + | |
0 | 12 | |
▼BrouteForceforMaxSUbarray.py
+14-0
| @@ -0,0 +1,14 @@ | ||
1 | +import math | |
2 | + | |
3 | +class Solution(object): | |
4 | + def maxSubarray(self,array): | |
5 | + max_sum = -math.inf | |
6 | + for start in range(len(array)): | |
7 | + arraysum=0 | |
8 | + for end in range(start,len(array)): | |
9 | + arraysum+=array[end] | |
10 | + max_sum=max(max_sum,arraysum) | |
11 | + | |
12 | + return max_sum | |
13 | + | |
14 | + | |
0 | 15 | |
▼DSA/Arrays/Reverse.py
+16-0
| @@ -0,0 +1,16 @@ | ||
1 | +class Solve: | |
2 | + def solve(array:list): | |
3 | + position1,position2=0,len(array)-1 | |
4 | + while position1<position2: | |
5 | + array[position1],array[position2]=array[position2],array[position1] | |
6 | + position1+=1 | |
7 | + position2-=1 | |
8 | + return array | |
9 | + | |
10 | + | |
11 | + | |
12 | + | |
13 | +array=[1,2,3,4,5,6,7,8] | |
14 | +print(Solve.solve(array)) | |
15 | + | |
16 | + | |
0 | 17 | |