Instantly share code, notes, and snippets.

View binary-tree-traversal.cpp
// Pre-order traversal
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
View floor-ceil.cpp
double floor(double x){
return (x >= 0) ? (int) x : (x == (int) x ? x : (int) x - 1);
}
double ceil(double x){
return (x >= 0) ? ((x == (int) x) ? (int) x : (int) x + 1) : ((x == (int) x) ? (int) x + 1 : (int) x);
}
View py-formatted-print.md
print("Dave have {} pens.".format(5))
Dave have 5 pens.
View to_str.cpp
std::string to_str(int num){
std::string str = "";
std::string nums[10];
nums[0] = "0"; nums[1] = "1"; nums[2] = "2"; nums[3] = "3"; nums[4] = "4";
nums[5] = "5"; nums[6] = "6"; nums[7] = "7"; nums[8] = "8"; nums[9] = "9";
if(num == 0) return nums[0];
int d = pow(10, 1.0 + floor(log10(num)));
while (d /= 10) str += nums[(num / d) % 10];