代码改变世界

阅读排行榜

[LeetCode]Search Insert Position

2014-03-14 11:13 by 庸男勿扰, 132 阅读, 收藏,
摘要: 原题链接:http://oj.leetcode.com/problems/search-insert-position/题意描述:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[ 阅读全文

[LeetCode]Pascal's Triangle

2014-03-15 23:23 by 庸男勿扰, 131 阅读, 收藏,
摘要: 原题链接:http://oj.leetcode.com/problems/pascals-triangle/题意描述:GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]题解: 两端为1,中间为v[i][j] = v[i-1][j-1]+v[i-1][j]; 1 class Solution { 2 public: 3 vector > ... 阅读全文

[LeetCode]Longest Common Prefix

2014-03-11 20:04 by 庸男勿扰, 130 阅读, 收藏,
摘要: 原题链接:http://oj.leetcode.com/problems/longest-common-prefix/题目描述:Write a function to find the longest common prefix string amongst an array of strings.题解: 依然是一道分治法解的题,类似的还有http://www.cnblogs.com/codershell/p/3592992.html 1 class Solution { 2 public: 3 string lcp(string str1,string str2){ 4 ... 阅读全文

[LeetCode]Binary Tree Postorder Traversal

2014-03-14 16:14 by 庸男勿扰, 123 阅读, 收藏,
摘要: 原题链接:http://oj.leetcode.com/problems/binary-tree-postorder-traversal/题意描述:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note:Recursive solution is trivial, could you do it iteratively?题解: 二叉树的后序遍历,... 阅读全文
上一页 1 ··· 3 4 5 6 7