This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def selection_sort(arr): | |
for i in range(len(arr)): | |
min_element_index = i | |
for j in range(i + 1, len(arr)): | |
if arr[j] < arr[min_element_index]: | |
min_element_index = j | |
arr[i], arr[min_element_index] = arr[min_element_index], arr[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quick_sort(arr,start, end): | |
if start < end: | |
pivot = partition(arr, start, end) | |
quick_sort(arr, start, pivot - 1) | |
quick_sort(arr, pivot + 1, end) | |
def partition(arr, start, end): | |
element = arr[start] | |
i = start | |
for j in range(start + 1, end): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_sort(arr): | |
if len(arr) > 1: | |
mid = len(arr) // 2 | |
left = arr[:mid] | |
right = arr[mid:] | |
merge_sort(left) | |
merge_sort(right) | |
merge(arr,left,right) | |
def merge(arr, left, right): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertion_sort(list: [int]) -> [int]: | |
for i in range(1, len(list)): | |
element = list[i] | |
j = i - 1 | |
while j >= 0 and element < list[j]: | |
list[j + 1] = list[j] | |
j -= 1 | |
list[j + 1] = element | |
return list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def sum_of_squares(self, n: int) -> int: | |
total = 0 | |
while n > 0: | |
total += (n % 10) ** 2 | |
n = int(n / 10) | |
return total | |
def isHappy(self, n: int) -> bool: | |
fast = self.sum_of_squares(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def sum_of_squares(self, n: int) -> int: | |
total = 0 | |
while n > 0: | |
total += (n % 10) ** 2 | |
n = int(n / 10) | |
return total | |
def isHappy(self, n: int) -> bool: | |
repeat_numbers = set() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def singleNumber(self, nums: List[int]) -> int: | |
nums_set = set() | |
for num in nums: | |
if num in nums_set: | |
nums_set.remove(num) | |
else: | |
nums_set.add(num) | |
return nums_set.pop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def singleNumber(self, nums: List[int]) -> int: | |
return reduce( lambda x, y: x ^ y, nums) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- MongoDB has a command named mongoimport which can be used to directly upload a CSV file into a particular collection of | |
a database with the first line of the csv as the keys and the following rest of the csv as the values for the respective keys | |
The format of mongoimport is as folllows | |
"mongoimport --db database_name --collection collection_name --file csv_file_name --type csv" | |
now we can use variables to store our database and collection's name. | |
we upload the file to get the filename and it's path and then simple substitute the database_name and collection_name etc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Your Database Connection include file here. | |
//This Entire PHP part can be placed in a seperate action file | |
//Upload File | |
if (isset($_POST['submit'])) { | |
//Upload Directory path. | |
$uploaddir = 'uploads/'; | |
//FilePath with File name. | |
$uploadfile = $uploaddir . basename($_FILES["filename"]["name"]); |
NewerOlder