BATMAN IS GRATE
swadhinbiswas committed 1 years ago
aaad9a6
1 parent 19f3c79
commit aaad9a6
6 files changed
+57 -13
Showing 6 changed files+57-13
▼ 88. Merge Sorted Arrary.py
+18-0
| @@ -0,0 +1,18 @@ | ||
1 | +from typing import List | |
2 | + | |
3 | +class Solution: | |
4 | + def merge(self,nums1: List[int], m: int, nums2: List[int], n: int) ->None: | |
5 | + """ | |
6 | + Do not return anything, modify nums1 in-place instead. | |
7 | + """ | |
8 | + j=0 | |
9 | + for i in range(m,len(nums1)): | |
10 | + nums1[i]=nums2[j] | |
11 | + j+=1;i+=1 | |
12 | + nums1=sorted(nums1) | |
13 | + | |
14 | + | |
15 | +# Aproch 2 | |
16 | + | |
17 | +class Solution: | |
18 | + def merge(self,nums1: List[int], m: int, nums2: List[int], n: int) ->None: | |
0 | 19 | |
▼ALGROTHMS/Sort.py
+19-1
| @@ -19,6 +19,22 @@ class Sorting: | ||
19 | 19 | array[i],array[small_element]=array[small_element],array[i] |
20 | 20 | return array |
21 | 21 | |
22 | + def insertionsort(array:List[int])->List[int]: | |
23 | + for i in range(1,len(array)): | |
24 | + current=array[i] | |
25 | + previous=i-1 | |
26 | + while previous>=0 and array[previous]>current: | |
27 | + array[previous+1]=array[previous] | |
28 | + previous-=1 | |
29 | + array[previous+1]=current | |
30 | + | |
31 | + return array | |
32 | + | |
33 | + | |
34 | + | |
35 | + | |
36 | + | |
37 | + | |
22 | 38 | |
23 | 39 | |
24 | 40 | |
| @@ -27,6 +43,8 @@ class Sorting: | ||
27 | 43 | |
28 | 44 | text=Sorting.bubbleshort([1,2,3,4,5]) |
29 | 45 | text2=Sorting.selectionssort([3,4,5,1,3,5,6,7,9]) |
46 | +text3=Sorting.insertionsort([3,4,5,1,3,5,6,7,9]) | |
30 | 47 | |
31 | 48 | print(text) |
32 | -print(text2) | |
49 | +print(text2) | |
50 | +print(text3) | |
33 | 51 | |
▼ALGROTHMS/heap.py
+0-0
0 | 0 |
▼Oh No! Classes!.py
+4-0
| @@ -0,0 +1,4 @@ | ||
1 | +testcase=int(input()) | |
2 | + | |
3 | +for i in range(testcase): | |
4 | + a,b | |
0 | 5 | |
▼aggrasivecow.py
+1-12
| @@ -1,12 +1 @@ | ||
1 | -from typing import List | |
2 | - | |
3 | -class Soluction: | |
4 | - def isPossibe(array:List[int],maxAllowed,cowsNumber)->bool: | |
5 | - cows=1;lastPositions=array[0] | |
6 | - for i in len(array): | |
7 | - if array[i]-lastPositions>=maxAllowed: | |
8 | - cows+=1 | |
9 | - lastPositions=array[i] | |
10 | - if cows==cowsNumber: | |
11 | - return True | |
12 | - | |
1 | +class Solution: | |
13 | 2 | |
▼os1s2s.py
+15-0
| @@ -0,0 +1,15 @@ | ||
1 | +class Solution: | |
2 | + def sortColors(self, nums: List[int]) -> None: | |
3 | + """ | |
4 | + Do not return anything, modify nums in-place instead. | |
5 | + """ | |
6 | + mid=0;start=0;end=len(nums)-1 | |
7 | + while(mid<=end): | |
8 | + if nums[mid]==0: | |
9 | + nums[start],nums[mid]=nums[mid],nums[start] | |
10 | + mid+=1;start+=1 | |
11 | + elif nums[mid]==1: | |
12 | + mid+=1 | |
13 | + else: | |
14 | + nums[end],nums[mid]=nums[mid],nums[end] | |
15 | + end-=1 | |
0 | 16 | |