原创 編程之美初賽-焦距(2014.4.19)

時間限制:2000ms 單點時限:1000ms 內存限制:256MB 描述 一般來說,我們採用針孔相機模型,也就是認爲它用到的是小孔成像原理。 在相機座標系下,一般來說,我們用到的單位長度,不是“米”這樣的國際單位,而是相鄰像素的長度。

原创 leetcode-Balanced Binary Tree(2014.1.27)

/**  * Definition for binary tree  * struct TreeNode {  *     int val;  *     TreeNode *left;  *     TreeNode *right;  

原创 Single Number(2014.2.7)

class Solution { public:     int singleNumber(int A[], int n) {         int x=A[0];         for(int i=1;i<n;i++){      

原创 leetcode-Jump Game(2014.2.23)

需要兩個計數,lastJump記載當前能跳最遠處,maxJump記錄實際能跳最遠距離。 class Solution { public:     bool canJump(int A[], int n) {         int la

原创 leetcode-Generate Parentheses (2014.4.18)

Generate Parentheses Total Accepted: 10265 Total Submissions: 33530 My Submissions Given n pairs of parentheses, write

原创 leetcode-Binary Tree Level Order Traversal II(2014.1.27)

此題可以遞歸?二叉樹是遞歸結構,層次遍歷則好像不是 /**  * Definition for binary tree  * struct TreeNode {  *     int val;  *     TreeNode *left;

原创 leetcode-Binary Tree Inorder Traversal(2014.1.23)

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

原创 leetcode-First Missing Positive(2014.2.25)

 哈希的思想是能夠在常數時間內進行查找,哈希函數是具體的實現方法,應當各有不同。 class Solution { public:     int firstMissingPositive(int A[], int n) {      

原创 leetcode-Candy(2014.2.25)

class Solution { public:     int candy(vector<int> &ratings) {         if(ratings.size()==0) return 0;         if(ratin

原创 leetcode-Add Two Numbers (2014.2.27)

細節很多,用了相當長的時間。代碼長度很長,不夠簡潔。 /**  * Definition for singly-linked list.  * struct ListNode {  *     int val;  *     ListN

原创 leetcode-Best Time to Buy and Sell Stock II(2014.2.17)

即是求整個波浪線的上升過程,解法略顯繁瑣,當可以直接採用判斷,若數組中元素後一個比前一個大,則不斷累加的方法。 class Solution { public:     int maxProfit(vector<int> &prices)

原创 leetcode-Add Binary(2014.3.3)

字符串的相關操作 class Solution { public:     string addBinary(string a, string b) {         int na=a.size();         int nb=b.

原创 leetcode OJ -Binary Tree Postorder Traversal(2014.1.20)

遞歸方法: /**  * Definition for binary tree  * struct TreeNode {  *     int val;  *     TreeNode *left;  *     TreeNode *ri

原创 leetcode-Best Time to Buy and Sell Stock(2014.2.17)

O(n)時間即可以完成 class Solution { public:     int maxProfit(vector<int> &prices) {         if(prices.size()<2) return 0;    

原创 leetcode-Binary Tree Level Order Traversal(2014.1.22)

//記載每一行有多少個節點,採用隊列結構 /**  * Definition for binary tree  * struct TreeNode {  *     int val;  *     TreeNode *left;  *