摘要: Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.tips: 1 remember not every dynamic programming need d[m+1][n+1] like this one.class Solution 阅读全文
posted @ 2013-01-11 08:45 西施豆腐渣 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.1. different from maximum depth. if a node only has one child, the depth will be 1 + child depth./** * Definition for binary tree * struct Tr. 阅读全文
posted @ 2013-01-11 08:25 西施豆腐渣 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ ... 阅读全文
posted @ 2013-01-11 07:55 西施豆腐渣 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 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 to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.class Solution { public: void merge(int A[], int m, int B[], int n) { ... 阅读全文
posted @ 2013-01-11 07:28 西施豆腐渣 阅读(137) 评论(0) 推荐(0) 编辑
摘要: Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18]./** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : start(0), end(0) {} * Interval(int s, int e) : st... 阅读全文
posted @ 2013-01-11 07:05 西施豆腐渣 阅读(136) 评论(0) 推荐(0) 编辑
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.keypoints: 1 be familiar with use of pointer to pointer ** pre, no need for a dummy head node.2. when the container need erase or insert, it's probably a sign of using list instead of vector.3. when u 阅读全文
posted @ 2013-01-11 04:38 西施豆腐渣 阅读(144) 评论(0) 推荐(0) 编辑