This file contains 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
### 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: |
This file contains 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
# | |
# https://leetcode.com/problems/decode-string/description/ | |
# | |
class Solution(object): | |
def decodeString(self, s): | |
""" | |
:type s: str | |
:rtype: str | |
""" | |
nums = [] # 3 |
This file contains 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 Queue: | |
def __init__(self): | |
self.array = [] | |
def is_empty(self): | |
return len(self.array) == 0 | |
def enqueue(self, value): | |
self.array.append(value) | |
This file contains 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
# | |
# https://leetcode.com/problems/valid-parentheses/description/ | |
# | |
class Solution(object): | |
def isValid(self, s): | |
""" | |
:type s: str | |
:rtype: bool | |
""" | |
open = ['(', '{', '['] |
This file contains 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 Stack: | |
def __init__(self): | |
self.items = [] | |
def isEmpty(self): | |
return [] | |
def push(self, item): | |
self.items.append([item]) |
This file contains 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
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): |
This file contains 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
Access (By index) - O(n) | |
Search (By value) - O(n) | |
Insertion - O(1) | |
Deletion - O(1) |
This file contains 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
/** | |
* 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; |
This file contains 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
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; | |
} |
This file contains 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
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) : |
NewerOlder