随笔分类 -  LeetCode Solutions

上一页 1 ··· 7 8 9 10 11 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:Again, a classic interview question of linked list. Similar to Linked List Cycle, we maintain two pointers fast and slow: fastmove two steps at one ti... 阅读全文
posted @ 2015-06-08 22:26 jianchao-li 阅读(197) 评论(0) 推荐(0)
摘要:A classic interview question of linked list. The idea is to maintain two pointers, one move one step at a time and the other move two steps at a time.... 阅读全文
posted @ 2015-06-08 22:06 jianchao-li 阅读(164) 评论(0) 推荐(0)
摘要:This problem has a long story. There are just too many solutions on the web and it can be studied for a long time before you fully grasp it. Morever, ... 阅读全文
posted @ 2015-06-08 21:57 jianchao-li 阅读(317) 评论(0) 推荐(0)
摘要:This is a classic problem for hash table. The basic idea is to maintain a hash table for each element innums, using the element as key and its index (... 阅读全文
posted @ 2015-06-08 17:22 jianchao-li 阅读(203) 评论(0) 推荐(0)
摘要:Well, this problem looks easy at first glance. However, to get a bug-free code may be not that easy.The total square is simply equal to the sum of the... 阅读全文
posted @ 2015-06-08 14:24 jianchao-li 阅读(326) 评论(0) 推荐(0)
摘要:Well, there many ways to solve this problem. Let's first look at a naive solution.The basic idea is simple. Starting from the first character of the s... 阅读全文
posted @ 2015-06-07 21:14 jianchao-li 阅读(213) 评论(0) 推荐(0)
摘要:The idea is to usetwo stacks.Forpush, the first stack records the pushed elements and the second stack recordsallthe minimum (including duplicates) th... 阅读全文
posted @ 2015-06-07 01:40 jianchao-li 阅读(200) 评论(0) 推荐(0)
摘要:This problem is an application of the Trie data structure. In the following, it is assumed that you have solvedImplement Trie (Prefix Tree).Now, let's... 阅读全文
posted @ 2015-06-07 01:13 jianchao-li 阅读(418) 评论(0) 推荐(0)
摘要:Well, the problem does not aim for an advanced algorithm like KMP but only a clean brute-force algorithm. So we can traverse all the possible starting... 阅读全文
posted @ 2015-06-06 22:27 jianchao-li 阅读(304) 评论(0) 推荐(0)
摘要:In this problem, we are asked to divide two integers. However, we are not allowed to use division, multiplication and mod operations. So, what else ca... 阅读全文
posted @ 2015-06-06 22:01 jianchao-li 阅读(202) 评论(0) 推荐(0)
摘要:To readncharacters, we first callread4forn / 4times. For example, if we want to read10characters, we will read them in the8 (4 * 2) + 2manner by first... 阅读全文
posted @ 2015-06-05 16:25 jianchao-li 阅读(271) 评论(0) 推荐(0)
摘要:Problem Description:Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data... 阅读全文
posted @ 2015-06-05 13:24 jianchao-li 阅读(260) 评论(0) 推荐(0)
摘要:The problem has a nice structure that backtracking naturally fits in. The structure is, given a starting positionidx, we search fromidxtill the end of... 阅读全文
posted @ 2015-06-04 20:35 jianchao-li 阅读(192) 评论(0) 推荐(0)
摘要:This problem is somewhat tricky at first glance. However, the final implementation is fairly simple using recursion.The basic idea is, visiting every ... 阅读全文
posted @ 2015-06-04 10:00 jianchao-li 阅读(270) 评论(0) 推荐(0)
摘要:Well, this problem desires for the use of dynamic programming. They key to any DP problem is to come up with the state equation. In this problem, we d... 阅读全文
posted @ 2015-06-03 11:54 jianchao-li 阅读(3690) 评论(0) 推荐(0)
摘要:Recursive (Backtracking)This is a typical problem that can be tackled by backtracking.Since backtracking has a more-or-less similar template, so I do ... 阅读全文
posted @ 2015-06-03 00:19 jianchao-li 阅读(224) 评论(0) 推荐(0)
摘要:This problem is similar toBest Time to Buy and Sell Stock. Givenprices, we find the day (denoted asbuy) of the first local minimum and the day (denote... 阅读全文
posted @ 2015-06-03 00:16 jianchao-li 阅读(189) 评论(0) 推荐(0)
摘要:This post shares a very simple solution, whose code is rewritten below, just 5 lines :-) 1 class Solution { 2 public: 3 int maxProfit(vector& pric... 阅读全文
posted @ 2015-06-03 00:14 jianchao-li 阅读(150) 评论(0) 推荐(0)
摘要:This problem seems to be tricky at first glance. However, if you know Morris traversal, it is just the preorder case of Morris traversal and the code ... 阅读全文
posted @ 2015-06-02 23:53 jianchao-li 阅读(190) 评论(0) 推荐(0)
摘要:There are many merge-sort solutions at the forum, but very few quicksort solutions. So I post my accepted quicksort solution here.Well, after reading ... 阅读全文
posted @ 2015-06-02 23:47 jianchao-li 阅读(205) 评论(0) 推荐(0)

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