随笔分类 -  Algorithm

摘要:Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol... 阅读全文
posted @ 2015-03-19 14:30 WinsCoder 编辑
摘要:Counting Sort1. Counting Sort doesn't work for negative number.2. Counting Sort assumes that each element is SMALL INTEGER.3. Time Complexity is O(Max... 阅读全文
posted @ 2015-02-23 16:18 WinsCoder 编辑
摘要:这篇文章的主题是动态规划, 主要介绍LeetCode中一维动态规划的题目, 列表如下:Climbing StairsDecode WaysUnique Binary Search TreesMaximum SubarrayMaximum Product SubarrayBest Time to Bu... 阅读全文
posted @ 2015-01-30 02:27 WinsCoder 编辑
摘要: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"tw... 阅读全文
posted @ 2015-01-30 02:23 WinsCoder 编辑
摘要:这篇文章的主题是动态规划, 主要介绍LeetCode中一维动态规划的题目, 列表如下:Climbing StairsDecode WaysUnique Binary Search TreesMaximum SubarrayMaximum Product SubarrayBest Time to Bu... 阅读全文
posted @ 2015-01-27 02:17 WinsCoder 编辑
摘要:Optimal substructureIncomputer science, a problem is said to haveoptimal substructureif an optimal solution can be constructed efficiently from optima... 阅读全文
posted @ 2014-12-05 05:49 WinsCoder 编辑
摘要:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant space so 阅读全文
posted @ 2014-01-30 07:48 WinsCoder 编辑
摘要: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-01-30 03:11 WinsCoder 编辑
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Code:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {pub... 阅读全文
posted @ 2014-01-29 09:39 WinsCoder 阅读(137) 评论(0) 推荐(0) 编辑
摘要:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, … ,ak) must 阅读全文
posted @ 2014-01-28 10:48 WinsCoder 编辑
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated number may be chosen fromCunlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, … ,ak 阅读全文
posted @ 2014-01-28 10:43 WinsCoder 编辑
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]Code:class Solution {public: void findCombination(int &n, int &k, int level, vector &buf, vector> &res){ if(buf. 阅读全文
posted @ 2014-01-28 10:23 WinsCoder 编辑
摘要:Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]Code:class Solu... 阅读全文
posted @ 2014-01-28 10:16 WinsCoder 编辑
摘要:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]Code:class Solution {public: ... 阅读全文
posted @ 2014-01-28 10:11 WinsCoder 编辑
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5,4,11,2]... 阅读全文
posted @ 2014-01-28 09:56 WinsCoder 编辑
摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文
posted @ 2014-01-28 09:49 WinsCoder 编辑
摘要:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文
posted @ 2014-01-28 09:24 WinsCoder 编辑
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文
posted @ 2014-01-28 09:10 WinsCoder 编辑
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Analysis: This approach cost time complexity O(n^3). 1. If points less than 2 or all points locate at the same position, just output the points number. 2. Find two points with different coordinates ... 阅读全文
posted @ 2013-12-13 14:36 WinsCoder 编辑
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13&qu 阅读全文
posted @ 2013-12-13 04:02 WinsCoder 编辑

点击右上角即可分享
微信分享提示