Skip to content

Commit 9f9dd51

Browse files
Added leetcode Solutions
1 parent e7590dc commit 9f9dd51

File tree

6 files changed

+117
-13
lines changed

6 files changed

+117
-13
lines changed

QuickSort.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Python program for implementation of Quicksort Sort
2+
3+
# This function takes last element as pivot, places
4+
# the pivot element at its correct position in sorted
5+
# array, and places all smaller (smaller than pivot)
6+
# to left of pivot and all greater elements to right
7+
# of pivot
8+
def partition(arr, low, high):
9+
i = (low - 1) # index of smaller element
10+
pivot = arr[high] # pivot
11+
12+
for j in range(low, high):
13+
# If current element is smaller than the pivot
14+
if arr[j] < pivot:
15+
16+
# increment index of smaller element
17+
i = i + 1
18+
arr[i], arr[j] = arr[j], arr[i]
19+
20+
arr[i + 1], arr[high] = arr[high], arr[i + 1]
21+
return i + 1
22+
23+
# The main function that implements QuickSort
24+
# arr[] --> Array to be sorted,
25+
# low --> Starting index,
26+
# high --> Ending index
27+
28+
# Function to do Quick sort
29+
def quick_sort(arr, low, high):
30+
if low < high:
31+
# pi is partitioning index, arr[p] is now
32+
# at right place
33+
pi = partition(arr, low, high)
34+
35+
# Separately sort elements before
36+
# partition and after partition
37+
quick_sort(arr, low, pi - 1)
38+
quick_sort(arr, pi + 1, high)
39+
40+
41+
# Driver code to test above
42+
if __name__ == '__main__':
43+
arr = [10, 7, 8, 9, 1, 5]
44+
n = len(arr)
45+
quick_sort(arr, 0, n - 1)
46+
print("Sorted array is:", arr)

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
# leetcode-solutions
2-
3-
# start contributing to this small open source project and learn how to contribute to projects.
4-
5-
# step 1: Fork this repository
6-
# step 2:Clone the repository
7-
# step 3:Create a branch
8-
# step 4:Make necessary changes and commit those changes
9-
# step 5:Push changes to GitHub
10-
# step 6: Submit your changes for review
11-
12-
13-
solve leetcode problems and add there solution file here as well.
1+
![Python-Hacktoberfest2021](https://socialify.git.ci/Krushna-Prasad-Sahoo/Python-Hacktoberfest2021/image?description=1&descriptionEditable=A%20beginner%20friendly%20repository%20for%20Hacktoberfest%202021%20where%20you%20can%20contribute%20programs%20in%20Python.&forks=1&issues=1&language=1&pulls=1&stargazers=1&theme=Dark)

palindromeCheck.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Check whether a string is palindrome or not using recursion
2+
3+
def palindrome(s):
4+
if len(s) < 1:
5+
return True
6+
else:
7+
if s[0] == s[-1]:
8+
return palindrome(s[1:-1])
9+
else:
10+
return False
11+
#input
12+
NewStr=input("Enter A String : ")
13+
14+
if palindrome(NewStr) == True:
15+
print("Its Palindrome")
16+
else:
17+
print("Not Palindrome")
18+

perform the binary search.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Python program to perform binary search
2+
def binary_search(arr, target):
3+
low = 0
4+
high = len(arr) - 1
5+
while low <= high:
6+
mid = (low + high) // 2
7+
if arr[mid] == target:
8+
return mid
9+
if arr[mid] > target:
10+
high = mid - 1
11+
else:
12+
low = mid + 1
13+
return -1
14+
15+
16+
arr = list(map(int,input().split()))
17+
target = int(input("Enter the item to be searched: "))
18+
result = binary_search(arr, target)
19+
if result == -1:
20+
print("Item not found")
21+
else:
22+
print("Item found at index: ", result)
23+

perform the linear search.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Python program to perform the linear search
2+
def linearsearch(lst, target):
3+
for i in range(len(lst)):
4+
if lst[i] == target:
5+
return i
6+
return -1
7+
8+
9+
lst = [7,5,48,15,9,5,123,45,35]
10+
item = int(input("Enter the item to be searched: "))
11+
index = linearsearch(lst, item)
12+
if index == -1:
13+
print("Item not found")
14+
else:
15+
print("Item found at index: ", index)

qrcode.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pyqrcode
2+
import png
3+
from pyqrcode import QRCode
4+
5+
6+
# String which represents the QR code
7+
s = "https://github.com/karandesai24"
8+
9+
# Generate QR code
10+
url = pyqrcode.create(s)
11+
12+
13+
# Create and save the png file naming "myqr.png"
14+
url.png('myqr.png', scale = 6)

0 commit comments

Comments
 (0)