原创 UVa 10935 - Throwing cards away I

鏈接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1876 題目描述:桌上有n(n<=50)

原创 leetcode:Rotate Array

class Solution { public: void rotate(int nums[], int n, int k) { k = k%n; reverse(nums,0,n-k-1

原创 代碼對齊

題目描述:輸入若干行代碼,要求各列單詞的左邊界對齊且儘量靠左。單詞之間至少要空一格。每個單詞不超過80個字符,每行不超過180個字符,一共最多1000行,樣例輸入與輸出如下: 輸入:   start:  integer;      //

原创 UVa: 12100 - Printer Queue

題目鏈接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3252 題目描述:有一些文件需要打印

原创 來說說二叉樹非遞歸遍歷

二叉樹的遍歷 早之前和同學聊天時,就提到了當時實習面試有一題就是要求非遞歸實現二叉樹遍歷,二叉樹本身就是一種通過遞歸定義的數據結構,所以用遞歸的方法遍歷二叉樹是很容易的,而二叉樹的遍歷又分爲前序遍歷,中序遍歷以及後序遍歷,其中非遞歸的算法

原创 leetcode:Symmetric Tree

非遞歸算法: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *r

原创 leetcode:Subsets

class Solution { public: vector<vector<int> > subsets(vector<int> &S) { vector<vector<int>> res; ve

原创 leetcode:Climbing Stairs

class Solution { public: int climbStairs(int n) { vector<int> table; table.push_back(0); ta

原创 leetcode:Binary Tree Inorder Traversal

class Solution { public: vector<int> inorderTraversal(TreeNode *root) { vector<int> res; stack<Tree

原创 leetcode:Divide Two Integers

class Solution { public: int divide(int dividend, int divisor) { long long div = dividend,dis = divisor;

原创 -2147483648

我們寫程序中可能會經常碰到overflow的情形,其中對-2147483648的處理一不小心就會出現數據overflow。 -2147483648 = -2^31,我們知道這是64位系統中int型能表示的最小值,這個時候我們要小心對其進

原创 leetcode:Binary Tree Preorder Traversal

class Solution { public: vector<int> preorderTraversal(TreeNode *root) { vector<int> res; stack<Tre

原创 opengl:凸包算法

準備工作 判斷點在有向線段的左側 可以通過叉積判斷,如下爲k在有向線段ab的左側代碼描述: double multiply(Point a, Point b, Point k) { double x1 = b.x-a.x;

原创 leetcode:Binary Tree Postorder Traversal

class Solution { public: vector<int> postorderTraversal(TreeNode *root) { vector<int> res; stack<pa

原创 leetcode:Sort Colors

1: class Solution { public: void sortColors(int A[], int n) { int b[3] = {0,0,0}; for(int i=0;i<n;i