Skip to content

Instantly share code, notes, and snippets.

View andreytwostep's full-sized avatar

Andrey Svyachenovskiy andreytwostep

View GitHub Profile
### Keybase proof
I hereby claim:
* I am andreytwostep on github.
* I am andrey_twostep (https://keybase.io/andrey_twostep) on keybase.
* I have a public key ASC12jHGmsgXjFoe8QeIn6C1j4UO8-ZxvXtGB4WaODCIBwo
To claim this, I am signing this object:
#
# https://leetcode.com/problems/decode-string/description/
#
class Solution(object):
def decodeString(self, s):
"""
:type s: str
:rtype: str
"""
nums = [] # 3
class Queue:
def __init__(self):
self.array = []
def is_empty(self):
return len(self.array) == 0
def enqueue(self, value):
self.array.append(value)
#
# https://leetcode.com/problems/valid-parentheses/description/
#
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
open = ['(', '{', '[']
class Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return []
def push(self, item):
self.items.append([item])
import time
f = open('./integers/1000.txt', 'r')
x = map(int, f.read().splitlines())
def solution(nums):
n = len(nums)
res = 0
for i in range(n):
for j in range(i + 1, n):
Access (By index) - O(n)
Search (By value) - O(n)
Insertion - O(1)
Deletion - O(1)
/**
* https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/
*/
var removeDuplicates = function(nums) {
var n = nums.length;
if (n <= 1) {
return n;
}
var unique = 0;
function arrayPairSum(nums) {
var sum = 0;
if (nums !== null && nums.length > 1) {
nums.sort();
for (var i = 0; i < nums.length; i += 2) {
sum += nums[i];
}
}
return sum;
}
function binarySearchRecursiveImpl(array $array, $find, $left, $right) {
if (count($array) < 1 || $left > $right) {
return -1;
}
$mid = floor(($left + $right) / 2);
if ($find == $array[$mid]) {
return $mid;
}
return $find > $array[$mid] ?
binarySearchRecursiveImpl($array, $find, $mid+1, $right) :