随笔分类 -  LeetCode Solutions

上一页 1 2 3 4 5 6 ··· 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:This problem can be solved in very neat codes (yeah, you will see Stefan posting many nice solutions).The solution in the above link is so nice that I... 阅读全文
posted @ 2015-10-06 22:10 jianchao-li 阅读(428) 评论(0) 推荐(0)
摘要:A solution using additional spaces to solve a copy of the original board is easy. To get an in-place solution, we need to record the information of st... 阅读全文
posted @ 2015-10-04 00:59 jianchao-li 阅读(706) 评论(0) 推荐(0)
摘要:Problem Description:An abbreviation of a word follows the form . Below are some examples of word abbreviations:a) it --> it (n... 阅读全文
posted @ 2015-10-02 00:30 jianchao-li 阅读(4247) 评论(0) 推荐(0)
摘要:There are mainly two solutions to solve this problem.The first one is very clever, using the idea of cycle detection, and runs in O(n) time. You may r... 阅读全文
posted @ 2015-09-28 17:26 jianchao-li 阅读(393) 评论(0) 推荐(0)
摘要:Problem Description:You are given am x n2D grid initialized with these three possible values.-1- A wall or an obstacle.0- A gate.INF- Infinity means a... 阅读全文
posted @ 2015-09-24 20:57 jianchao-li 阅读(3913) 评论(0) 推荐(1)
摘要:Problem Description:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in... 阅读全文
posted @ 2015-09-22 15:59 jianchao-li 阅读(3581) 评论(0) 推荐(0)
摘要:An interesting problem about iterators. This post shares a very nice solution, which is rewritten below, with minor simplifications.// Below is the in... 阅读全文
posted @ 2015-09-21 12:18 jianchao-li 阅读(396) 评论(0) 推荐(0)
摘要:This post shares a very nice solution, which is rewritten below. 1 class Solution { 2 public: 3 vector addOperators(string num, int target) { 4 ... 阅读全文
posted @ 2015-09-16 21:58 jianchao-li 阅读(473) 评论(0) 推荐(0)
摘要:The key challenge to this problem is to make the code clean. This post has shared a nice example, which is rewritten below in C++.class Solution {publ... 阅读全文
posted @ 2015-09-14 14:53 jianchao-li 阅读(225) 评论(0) 推荐(0)
摘要:Problem Description:Given two 1d vectors, implement an iterator to return their elements alternately.For example, given two 1d vectors:v1 = [1, 2]v2 =... 阅读全文
posted @ 2015-09-14 14:16 jianchao-li 阅读(2482) 评论(0) 推荐(0)
摘要:Problem Description:Given an unsorted arraynums, reorder itin-placesuch thatnums[0] = nums[2] = nums[i - 1];Ifiis even, thennums[i] & nums) {4 ... 阅读全文
posted @ 2015-09-10 12:57 jianchao-li 阅读(2472) 评论(0) 推荐(0)
摘要:Well, after seeing the similar problems, you may have known how to solve this problem. Yeah, just to construct larger numbers from smaller numbers by ... 阅读全文
posted @ 2015-09-09 22:47 jianchao-li 阅读(614) 评论(0) 推荐(0)
摘要:This post shares a nice explanation, which is implemented here. The code is rewritten below. 1 class Solution { 2 public: 3 string minWindow(strin... 阅读全文
posted @ 2015-09-08 18:42 jianchao-li 阅读(213) 评论(0) 推荐(0)
摘要:This problem is relatively easy. The challenge is how to get a concise code. This post shares a very elegant one which traverses each cell of board on... 阅读全文
posted @ 2015-09-08 17:51 jianchao-li 阅读(231) 评论(0) 推荐(0)
摘要:Just don't be scared by this problem :-) It's also very standard backtracking problem. This post shares a very concise code, which is rewritten below ... 阅读全文
posted @ 2015-09-08 17:35 jianchao-li 阅读(227) 评论(0) 推荐(0)
摘要:Just use binary search to find the first bad version.The code is as follows. 1 // Forward declaration of isBadVersion API. 2 bool isBadVersion(int ver... 阅读全文
posted @ 2015-09-07 21:52 jianchao-li 阅读(184) 评论(0) 推荐(0)
摘要:Problem Description: Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition 阅读全文
posted @ 2015-09-06 22:43 jianchao-li 阅读(1285) 评论(0) 推荐(0)
摘要:Problem Description:There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more... 阅读全文
posted @ 2015-09-05 12:24 jianchao-li 阅读(4208) 评论(0) 推荐(1)
摘要:This problem is designed specifically to use binary search. In fact, in H-Index, someone has already used this idea (you may refer to this post :-))Th... 阅读全文
posted @ 2015-09-04 22:19 jianchao-li 阅读(264) 评论(0) 推荐(0)
摘要:If you've read the Wikipedia article of H-Index, there is already a neat formula there for computing the h-index, which is written below using the not... 阅读全文
posted @ 2015-09-04 22:15 jianchao-li 阅读(414) 评论(0) 推荐(0)

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