上一页 1 ··· 6 7 8 9 10 11 下一页

2014年3月3日

Convert Sorted Array to Binary Search Tree

摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.提交一直无法通过,应该是声明TreeNode时候出现的问题。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} *... 阅读全文

posted @ 2014-03-03 15:25 pengyu2003 阅读(121) 评论(0) 推荐(0)

2014年3月1日

3-1

摘要: 不知不觉3月1日了,离实习的时间越来越近,论文还没有开搞,略急啊……刷了4道题,星期天休息~~Valid Number调了2小时不通,打算放弃来着,文清说了一句“你就这么放弃了?”,又坐回来重新调,结果20分钟调好了……羞愧啊……这题需要考虑的东西好多,以后拿来锻炼思维缜密度。Add Binary就是熟练下stringClimbing Stairs用了3个int的常驻内存空间,不知道有没有用的更少的算法?Merge Sorted Array昨天晚上的mergesort真是没白看,不申请多余内存空间,尽量减少数据移动次数。难得天这么蓝,好想出去兜风啊~~老老实实看书明天再疯吧! 阅读全文

posted @ 2014-03-01 15:26 pengyu2003 阅读(97) 评论(0) 推荐(0)

Merge Sorted Array

摘要: Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal tom+n) to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.非常水题。不过需要注意后面的补全。练习过mergesort()都不会多申请内存 阅读全文

posted @ 2014-03-01 15:14 pengyu2003 阅读(164) 评论(0) 推荐(0)

Climbing Stairs

摘要: You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?动态规划大水题。类似斐波那契额数列。class Solution {public: int climbStairs(int n) { if(n == 0 || n == 1|| n == 2)return n; int a =... 阅读全文

posted @ 2014-03-01 14:50 pengyu2003 阅读(115) 评论(0) 推荐(0)

Add Binary

摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".很简单的题,代码写麻烦了。注意string加的顺序。class Solution {public: string addBinary(string a, string b) { int la = a.length()-1; int lb = b.length()-1; string re; int flag = 0; ... 阅读全文

posted @ 2014-03-01 14:33 pengyu2003 阅读(149) 评论(0) 推荐(0)

Valid Number

摘要: alidate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing 阅读全文

posted @ 2014-03-01 14:08 pengyu2003 阅读(202) 评论(0) 推荐(0)

2014年2月28日

2-28

摘要: 今天也只刷了4道题。1.需要注意string不是char*,直接在对应位置赋值最终不会正确返回string2.求区间的题比求位置的题需要多注意一下,返回的位置是靠前还是靠后。 阅读全文

posted @ 2014-02-28 20:01 pengyu2003 阅读(83) 评论(0) 推荐(0)

Unique Paths

摘要: A robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many possible uni 阅读全文

posted @ 2014-02-28 19:57 pengyu2003 阅读(110) 评论(0) 推荐(0)

Count and Say

摘要: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte 阅读全文

posted @ 2014-02-28 16:33 pengyu2003 阅读(136) 评论(0) 推荐(0)

Valid Sudoku

摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.Note:A valid Sudoku board (partially filled) is not necessarily solvable. Only the f 阅读全文

posted @ 2014-02-28 15:13 pengyu2003 阅读(148) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 下一页

导航