随笔分类 -  LeetCode Solutions

上一页 1 2 3 4 5 6 7 ··· 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:This link shares a nice solution with explanation using DP. You will be clear of the algorithm after running it on its suggested example:matrix = [[0,... 阅读全文
posted @ 2015-09-02 12:18 jianchao-li 阅读(227) 评论(0) 推荐(0)
摘要:The basic idea is as follows:Create anew_headthat points toheadand use it to locate the immediate node before them-th (notice that it is1-indexed) nod... 阅读全文
posted @ 2015-09-01 23:55 jianchao-li 阅读(159) 评论(0) 推荐(0)
摘要:This link has a very neat code, which is rewritten below using stacksince thepushandpopoperations of it areO(1)time, while thepop_backandpush_backofve... 阅读全文
posted @ 2015-09-01 21:20 jianchao-li 阅读(213) 评论(0) 推荐(0)
摘要:This problem is not difficult. But it is not easy to have a bug-free code. As you write your codes according to the hints, the most important thing is... 阅读全文
posted @ 2015-08-31 20:52 jianchao-li 阅读(689) 评论(0) 推荐(0)
摘要:Problem Description:Given a non-empty binary search tree and a target value, findkvalues in the BST that are closest to the target.Note:Given target v... 阅读全文
posted @ 2015-08-30 18:50 jianchao-li 阅读(4119) 评论(0) 推荐(0)
摘要:Problem Description:Design an algorithm to encodea list of stringstoa string. The encoded string is then sent over the network and is decoded back to ... 阅读全文
posted @ 2015-08-29 12:22 jianchao-li 阅读(4728) 评论(0) 推荐(0)
摘要:An interesting problem. The code is also short and clear.The basic idea is to use a 2d array dp[i][j] to denote the minimum hp that is required before... 阅读全文
posted @ 2015-08-27 18:15 jianchao-li 阅读(498) 评论(0) 推荐(0)
摘要:Problem Description:Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:Given target... 阅读全文
posted @ 2015-08-27 14:28 jianchao-li 阅读(2901) 评论(0) 推荐(0)
摘要:Problem Description:There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a li... 阅读全文
posted @ 2015-08-25 21:39 jianchao-li 阅读(15854) 评论(3) 推荐(0)
摘要:This link has two nice solutions, one updating from forth to back (posted by tqlong in the post) and the other updating from back to forth (posted by ... 阅读全文
posted @ 2015-08-24 18:27 jianchao-li 阅读(244) 评论(0) 推荐(0)
摘要:There are three methods to solve this problem: bit manipulation, rearrangement of the array, and math tricks.Bit Manipulation1 class Solution {2 publi... 阅读全文
posted @ 2015-08-24 11:32 jianchao-li 阅读(256) 评论(0) 推荐(0)
摘要:Problem Description:Given a strings, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permut... 阅读全文
posted @ 2015-08-23 10:59 jianchao-li 阅读(3840) 评论(0) 推荐(0)
摘要:Problem Description:Given a string, determine if a permutation of the string could form a palindrome.For example,"code"-> False,"aab"-> True,"carerac"... 阅读全文
posted @ 2015-08-21 17:41 jianchao-li 阅读(4063) 评论(0) 推荐(0)
摘要:The idea and code is just taken from this link. There is a nice explanation to the code on the answer byBrianLuong1337. 1 class Solution { 2 public: 3... 阅读全文
posted @ 2015-08-20 00:58 jianchao-li 阅读(231) 评论(0) 推荐(0)
摘要:Stefan is a hero! Personally, I love his first C++ solution. 1 class Solution { 2 public: 3 int nthUglyNumber(int n) { 4 vector ugly(n, 1)... 阅读全文
posted @ 2015-08-19 16:32 jianchao-li 阅读(245) 评论(0) 推荐(0)
摘要:No matter what language you use on the OJ, you may refer to Stefan's post for a solution. The C++ is rewritten below, just really concise.1 class Solu... 阅读全文
posted @ 2015-08-19 16:28 jianchao-li 阅读(213) 评论(0) 推荐(0)
摘要:The idea is very simple: just extract the numbers from each version number and compare the numbers from beginning to the end. However, C++ seems to ha... 阅读全文
posted @ 2015-08-18 22:31 jianchao-li 阅读(309) 评论(0) 推荐(0)
摘要:The basic idea is to store the key-value pair in some container. In the following code, we make three type definitions:1 typedef list LI;2 typedef pai... 阅读全文
posted @ 2015-08-18 21:53 jianchao-li 阅读(345) 评论(0) 推荐(0)
摘要:The idea is similar to Strobogrammatic Number II: generate all those in-range strobogrammatic numbers and count.You may refer to this link for a very ... 阅读全文
posted @ 2015-08-18 15:04 jianchao-li 阅读(1607) 评论(0) 推荐(0)
摘要:Problem Description:Givennnodes labeled from0ton - 1and a list of undirected edges (each edge is a pair of nodes), write a function to check whether t... 阅读全文
posted @ 2015-08-18 10:58 jianchao-li 阅读(3487) 评论(0) 推荐(1)

上一页 1 2 3 4 5 6 7 ··· 12 下一页