Skip to content

Instantly share code, notes, and snippets.

<?php
class SharedArray extends Stackable {
public function __construct($array) {
$this->merge($array);
}
public function run(){}
}
<?php
$a = array(1,2,5,9,8,7,4,5,6,5,8,15,10,25,85,4,1,2,78,9);
function qsort(array &$a, $low, $high)
{
if ($low < $high){
$pivot = partition($a, $low, $high);
qsort($a, $low, $pivot - 1);
qsort($a, $pivot + 1, $high);
<?php
trait Singleton
{
private static $_instance = null;
public static function getInstance()
{
if (is_null(self::$_instance)) {
self::$_instance = new static();
#!/usr/bin/env python
import sys
def main(list):
dict = {}
if len(list) == 0:
return None
common = list[0]
for element in list:
#!/usr/bin/env python
import sys
def main(list):
dict = {}
memo = unique = set()
if len(list) == 0:
return None
#!/usr/bin/env python
import sys
import networkx as nx
from collections import deque
def bfs(graph):
queue = deque([])
queue.append(graph.nodes()[0])
import sys
def quicksort(list, lo=None, hi=None):
if lo is None:
lo, hi = 0, len(list)-1
if lo < hi:
pivot = partition(list, lo, hi)
quicksort(list, lo, pivot-1)
quicksort(list, pivot + 1, hi)
def binsearch(needle, haystack):
lo, hi, found = 0, len(haystack)-1, None
while lo <= hi and found is None:
mid = lo + (hi - lo) // 2
if haystack[mid] == needle:
found = mid
if haystack[mid] < needle:
lo = mid + 1
else:
hi = mid - 1
def pascal_triangle(n):
prev = []
for row in xrange(n):
curr = [1]
for index in xrange(1, row):
curr.append(prev[index-1] + prev[index])
if row > 0: curr.append(1)
print curr
prev = curr
def lcs_length(a, b):
table = [[0] * (len(b) + 1)] * (len(a) + 1)
for i, ca in enumerate(a, 1):
for j, cb in enumerate(b, 1):
table[i][j] = (
table[i - 1][j - 1] + 1 if ca == cb else
max(table[i][j - 1], table[i - 1][j]))
return table[-1][-1]