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
# (){}[] | |
def isBalancedParenthesis(str): | |
stack = [] | |
for i in str: | |
if i == '(' or i == '{' or i == '[': | |
stack.append(i) | |
elif i == ')' or i == '}' or i == ']': |
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 os | |
def listAllFiles(path): | |
files = [] | |
try: | |
for i in os.listdir(path): | |
files.append(i) | |
except FileNotFoundError: | |
print('File not found') |
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
/** | |
* Created by Hoan Nguyen on 10/29/2017. | |
*/ | |
const fsp = require('fs-promise'); | |
(async () => { | |
try { | |
const txt = await fsp.readFile('./input.txt', 'utf8'); | |
console.log(txt); | |
} catch (e) { |
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
/** | |
* Created by Hoan Nguyen on 10/28/2017. | |
*/ | |
var isMomHappy = true; | |
// Promise | |
var willIGetNewPhone = new Promise( | |
function(resolve, reject) { | |
if (isMomHappy) { | |
var phone = { |
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 findMaxOccurence(str) { | |
var map = new Map(); | |
var max = 0; | |
for (var i = 0; i < str.length; i++) { | |
if (map.has(str.charAt(i))) { | |
map.set(str.charAt(i), map.get(str.charAt(i)) + 1); | |
} else { | |
map.set(str.charAt(i), 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
import time | |
def timing_function(some_function): | |
""" | |
Outputs the time a function takes | |
to execute. | |
""" | |
def wrapper(): |
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
## Implement Queue in Python | |
class Queue(): | |
def __init__(self): | |
self.arr = [] | |
def push(self, item): | |
self.arr.insert(0, item) | |
def pop(self): |
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.arr = [] | |
def push(self, item): | |
self.arr.append(item) | |
def pop(self): | |
if self.arr: | |
self.arr.pop() |
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
def isTangle(a, b, c): | |
if a <= 0 or b <= 0 or c <= 0: | |
return False | |
else: | |
if a + b >= c and a + c >= b and a <= b + c: | |
return True | |
def showInfo(): | |
count = 5 |
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
def sumOfDigits(str): | |
temp = '' | |
sum = 0 | |
for i in range(len(str)): | |
if str[i].isdigit(): | |
temp += str[i] | |
else: | |
if temp.isdigit(): | |
sum += int(temp) |