随笔分类 -  LeetCode Solutions

上一页 1 ··· 5 6 7 8 9 10 11 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:1 /** 2 * Definition of ListNode 3 * class ListNode { 4 * public: 5 * int val; 6 * ListNode *next; 7 * ListNode(int val) { 8 * ... 阅读全文
posted @ 2015-06-29 23:11 jianchao-li 阅读(262) 评论(0) 推荐(0)
摘要:Well, life gets difficult pretty soon whenever the same operation on array is transferred to linked list.First, a quick recap of insertion sort:Start ... 阅读全文
posted @ 2015-06-29 23:07 jianchao-li 阅读(171) 评论(0) 推荐(0)
摘要:Well, to compute the number of trailing zeros, we need to first think clear about what will generate a trailing0? Obviously, a number multiplied by10w... 阅读全文
posted @ 2015-06-28 16:52 jianchao-li 阅读(277) 评论(0) 推荐(0)
摘要:Well, the basic idea is very simple. Start from the tail ofsand move backwards to find the first non-space character. Then from this character, move b... 阅读全文
posted @ 2015-06-28 16:11 jianchao-li 阅读(172) 评论(0) 推荐(0)
摘要:Well, this problem is spiritually similar to toCourse Schedule. You only need to store the nodes in the order you visit into a vector during BFS or DF... 阅读全文
posted @ 2015-06-28 02:39 jianchao-li 阅读(373) 评论(0) 推荐(0)
摘要:As suggested by the hints, this problem is equivalent to detecting a cycle in the graph represented byprerequisites. Both BFS and DFS can be used to s... 阅读全文
posted @ 2015-06-28 01:01 jianchao-li 阅读(287) 评论(0) 推荐(0)
摘要:Problem Description:Given two strings S and T, determine if they are both one edit distance apart.To solve this problem, you first need to know what i... 阅读全文
posted @ 2015-06-26 15:52 jianchao-li 阅读(978) 评论(0) 推荐(0)
摘要:This problem is similar to Missing Ranges and easier than that one.The idea is to use two pointers to find the beginning and end of a range and then p... 阅读全文
posted @ 2015-06-26 14:29 jianchao-li 阅读(283) 评论(0) 推荐(0)
摘要:Well, the key to this problem is on how to identify the recurring parts. After doing some examples using pen and paper, you may find that for the deci... 阅读全文
posted @ 2015-06-25 22:20 jianchao-li 阅读(296) 评论(0) 推荐(0)
摘要:The problem statement has stated that there are bothO(n)andO(nlogn)solutions to this problem. Let's see theO(n)solution first (taken fromthis link), w... 阅读全文
posted @ 2015-06-25 17:33 jianchao-li 阅读(240) 评论(0) 推荐(0)
摘要:Problem Description:Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.The input string d... 阅读全文
posted @ 2015-06-25 16:56 jianchao-li 阅读(243) 评论(0) 推荐(0)
摘要:This link has a great discussion about this problem. You may refer to it if you like. In fact, the idea and code in this passage is from the former li... 阅读全文
posted @ 2015-06-25 15:28 jianchao-li 阅读(799) 评论(0) 推荐(0)
摘要:Well, this problem has a nice BFS structure.Let's see the example in the problem statement.start = "hit"end = "cog"dict = ["hot", "dot", "dog", "lot",... 阅读全文
posted @ 2015-06-25 01:00 jianchao-li 阅读(316) 评论(0) 推荐(0)
摘要:This problem is not quite difficult (a typical BFS traversal of graph), though, its aceptance rate is relatively low. In fact, the key obstacle in pas... 阅读全文
posted @ 2015-06-24 19:09 jianchao-li 阅读(230) 评论(0) 推荐(0)
摘要:This problem is an application of graph traversal, which has two systematic methods:Bread-First Search (BFS)andDepth-First Search (DFS). In the follow... 阅读全文
posted @ 2015-06-24 16:03 jianchao-li 阅读(204) 评论(0) 推荐(0)
摘要:To solve this problem, some observations have to be made first.Let's first see two relatively easy observations.To maximize the probability that we ca... 阅读全文
posted @ 2015-06-24 00:51 jianchao-li 阅读(362) 评论(0) 推荐(0)
摘要:This is a typical problem aboutsearching. In fact, you can use either BFS or DFS for it. Personally, I use BFS because I think it is more intuitive an... 阅读全文
posted @ 2015-06-23 20:25 jianchao-li 阅读(238) 评论(0) 推荐(0)
摘要:The basic idea of is as follows:Maintain a dequeoperandsfor the numbers and another dequeoperationsfor the operators+, -, *,/`.Scan the expression fro... 阅读全文
posted @ 2015-06-22 23:27 jianchao-li 阅读(314) 评论(0) 推荐(0)
摘要:Well, a typical backtracking problem. Make sure you are clear with the following three problems:What is a partial solution and when is it finished? --... 阅读全文
posted @ 2015-06-18 00:23 jianchao-li 阅读(201) 评论(0) 推荐(0)
摘要:Well, a typical backtracking problem. Make sure you are clear with the following three problems:What is a partial solution and when is it finished? --... 阅读全文
posted @ 2015-06-16 23:57 jianchao-li 阅读(260) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 12 下一页