Still a DP problem.The transition function is not hard to get:1. When s[i-1] == t[j-1], which means we dont have to do any thing to handle the current...
分类:
其他好文 时间:
2015-03-19 09:52:36
阅读次数:
104
Since it need the min value of initial health, this dp tracks from the back to the start.The trick is either this knight has 1 health or base on next ...
分类:
其他好文 时间:
2015-03-19 08:51:07
阅读次数:
138
This DP is a little bit tricky. You need to clear that:when S[i-1] == T[j-1], it has two part :1. dp[i-1][j-1], this means from 0 - j-1, it already ma...
分类:
其他好文 时间:
2015-03-19 08:50:24
阅读次数:
147
There couple of edge cases need to remember:1. The result, absolute value of dividend and divisor. Otherwise, when the record goes out of boundary, th...
分类:
其他好文 时间:
2015-03-19 08:50:24
阅读次数:
125
Pretty straight forward. count numbers and put char. 1 class Solution { 2 public: 3 string getNext(string s) { 4 ostringstream oss; 5 ...
分类:
其他好文 时间:
2015-03-19 07:47:22
阅读次数:
129
Simple DP.Scanning from the end. If current is 0, then no ways as "0", but it can be treated as "10", "20". So do another check whether it can has oth...
分类:
其他好文 时间:
2015-03-19 07:45:43
阅读次数:
148
Two methods for doing this problem:1. With extra memory, using hashtable:I made a mistake for mapping[runner->random] = mapping[runner]->random. Then ...
分类:
其他好文 时间:
2015-03-19 07:44:36
阅读次数:
132
The minimum height controls the volumns. So let two runner at two ends start to scan the array. 1 class Solution { 2 public: 3 int maxArea(vector ...
分类:
其他好文 时间:
2015-03-19 06:21:12
阅读次数:
147
It is kind of binary search. Since this is a sorted array, we can treat it as inorder traversal. And we can define the root node for the Tree.So find ...
分类:
其他好文 时间:
2015-03-19 06:19:48
阅读次数:
105
1. Use BFS to search the graph.2. Create a hashtable to record the one to one mapping. 1 /** 2 * Definition for undirected graph. 3 * struct Undirec.....
分类:
其他好文 时间:
2015-03-19 06:19:16
阅读次数:
125