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
""" | |
Problem: | |
PASS TRIANGLE | |
CHALLENGE DESCRIPTION: | |
By starting at the top of the triangle and moving to adjacent numbers on the row below, the maximum total from top to bottom is 27. | |
5 | |
9 6 |
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
''' | |
Sequence 011212201220200112 ... constructed as follows: first is 0, then repeated the following action: already written part is attributed to the right with replacement 0 to 1, 1 to 2, 2 to 0. E.g. | |
0 -> 01 -> 0112 -> 01121220 -> ... | |
Create an algorithm which determines what number is on the N-th position in the sequence. | |
INPUT SAMPLE: | |
Your program should accept as its first argument a path to a filename. Each line in this file contains an integer N such as | |
0 <= N <= 3000000000. E.g. |
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
''' | |
Given an array of integers, every element appears twice except for one. Find that single one. | |
''' | |
class Solution: | |
# @param A, a list of integer | |
# @return an integer | |
def singleNumber(self, A): | |
A.sort() |
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
''' | |
Given two binary trees, write a function to check if they are equal or not. | |
Two binary trees are considered equal if they are structurally identical and the nodes have the same value. | |
''' | |
# Definition for a binary tree node | |
# class TreeNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None |
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 Solution: | |
# @param prices, a list of integer | |
# @return an integer | |
def addr(self,x,y): | |
return (x + y) | |
def maxProfit(self, prices): | |
if not prices: | |
return 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
#include<iostream> | |
using namespace std; | |
int rand_gen(unsigned int x) { | |
/* | |
XOR Linear feedback shift register based random gen | |
*/ | |
unsigned int a=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
''' | |
Create a tree out of a list of tuples - (data,depth) | |
Constraint: The new level node should be added to the latest of the old level node | |
ex: | |
if the tuple is: | |
(a,1) | |
(b,2) | |
(c,2) | |
(d,3) | |
(e,2) |