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
from typing import List | |
def quick_select(array: List, start: int, end: int, kth: int): | |
if start > end: | |
return | |
pivot = partition(array, start, end) | |
if pivot == kth - 1: |
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
from typing import List | |
def quick_sort(array: List, start: int, end: int) -> None: | |
if start >= end: | |
return | |
pivot = partition(array, start, end) | |
quick_sort(array, start, pivot - 1) | |
quick_sort(array, pivot + 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
class DisjointSet: | |
sets = {} | |
rank = {} | |
def __init__(self, arr): | |
for v in arr: | |
self.sets[v] = v | |
self.rank[v] = 0 | |
def merge(self, v1, v2): |
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 | |
namespace App\Traits; | |
use Illuminate\Support\Facades\DB; | |
trait MySQLUpsert | |
{ | |
/** | |
* Single call to insert/update based on any duplicate key (primary, unique, 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
class tower_of_hanoi: | |
tower1 = None | |
tower2 = None | |
tower3 = None | |
def __init__(self, n): | |
self.tower1 = Stack | |
self.tower2 = Stack | |
self.tower3 = Stack | |
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 Node: | |
visited = None | |
data = None | |
adjacent = None | |
def __init__(self, value): | |
self.data = value | |
self.adjacent = [] | |
self.visited = False |
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 Node: | |
visited = None | |
data = None | |
adjacent = None | |
def __init__(self, value): | |
self.data = value | |
self.adjacent = [] | |
self.visited = False | |
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
[alias] | |
merge-release-major = !sh ../gitscripts/merge-release-major.sh | |
merge-release-minor = !sh ../gitscripts/merge-release-minor.sh | |
merge-release-patch = !sh ../gitscripts/merge-release-patch.sh |
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(array: List) -> List: | |
if len(array) < 2: | |
return array | |
middle = floor(len(array)/2) | |
left = merge_sort(array[:middle]) | |
right = merge_sort(array[middle:]) | |
sorted_array = [] |
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 bubble_sort(array): | |
for i in range(0, len(array)): | |
swapped = False | |
for j in range(0, len(array) - i - 1): | |
if array[j] > array[j + 1]: | |
array[j], array[j + 1] = array[j + 1], array[j] | |
swapped = True | |
if not swapped: |
NewerOlder