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 Solution { | |
| private: | |
| int fact(int n) { | |
| int ans = 1; | |
| for(int i = 1; i <= n; ++i) ans *= i; | |
| return ans; | |
| } | |
| public: | |
| vector<vector<int>> permute(vector<int>& nums) { | |
| const int n = nums.size(); |
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 Solution { | |
| public: | |
| vector<vector<int>> generate(int numRows) { | |
| vector<vector<int>> result; | |
| if(!numRows) return {}; | |
| result.push_back({1}); | |
| for(int i = 0; i < numRows-1; i++){ | |
| vector<int> row; | |
| vector<int> prevRow = result.back(); | |
| for(int k = 0; k < prevRow.size(); k++){ |
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
| """ | |
| # Definition for a Node. | |
| class Node(object): | |
| def __init__(self, val, children): | |
| self.val = val | |
| self.children = children | |
| """ | |
| class Solution(object): | |
| def preorder(self, root): | |
| """ |
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
| # Definition for a binary tree node. | |
| # class TreeNode: | |
| # def __init__(self, x): | |
| # self.val = x | |
| # self.left = None | |
| # self.right = None | |
| class Solution: | |
| def lowestCommonAncestor(self, root, p, q): | |
| """ |
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
| # Definition for singly-linked list. | |
| # class ListNode: | |
| # def __init__(self, x): | |
| # self.val = x | |
| # self.next = None | |
| class Solution: | |
| def isPalindrome(self, head): |
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 solve_towers(n_disks, source, dest, helper): | |
| if n_disks == 0: | |
| return | |
| solve_towers(n_disks-1, source, helper, dest) | |
| move_disks(n_disks-1, source, dest) | |
| solve_towers(n_disks-1, helper, dest, source) | |
| def move_disks(n_disks, source, dest): | |
| print("Moving disk {} from {} -> {}".format(n_disks, source, dest)) |
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
| execute pathogen#infect() | |
| syntax on | |
| filetype plugin indent on | |
| set cursorline | |
| set number | |
| set noerrorbells | |
| set title | |
| let g:solarized_termcolors=16 | |
| set t_Co=16 |
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 circ_queue(object): | |
| """docstring for circ_queue.""" | |
| queue = [] | |
| head = 0 | |
| tail = 0 | |
| len = 0 | |
| def __init__(self, max_len = 8): | |
| super(circ_queue, self).__init__() | |
| self.queue = [None] * max_len | |
| self.len = max_len |
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
| import os | |
| import struct | |
| import numpy as np | |
| """ | |
| Python3 friendly version of the following work: | |
| https://gist.github.com/akesling/5358964 | |
| """ | |
| def read(dataset = "training", path = "Data"): |