摘要: Well, it seems that many people meet the TLE problem. Well, I use a simple trick in my code to aoivd TLE. That is, each time before I try to breaks, I... 阅读全文
posted @ 2015-06-10 09:39 jianchao-li 阅读(313) 评论(0) 推荐(0) 编辑
摘要: Well, an extension of Remove Duplicates from Sorted Array.The program is fairly similar to that in this solution.1 int removeDuplicates(vector& nu... 阅读全文
posted @ 2015-06-09 21:39 jianchao-li 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Well, a medium problem. Use two pointers. One points to the curren number and the other points to the last unique number. Once duplicates occur, move ... 阅读全文
posted @ 2015-06-09 21:30 jianchao-li 阅读(172) 评论(0) 推荐(0) 编辑
摘要: Radix sort is another linear time sorting algorithm. It sorts (using another sorting subroutine) the numbers from their least significant digits to mo... 阅读全文
posted @ 2015-06-09 20:48 jianchao-li 阅读(289) 评论(0) 推荐(0) 编辑
摘要: Well, this problem is designed for radix sort. For more information about radix sort, Introduction to Algorithms, 3rd edition has some nice examples.H... 阅读全文
posted @ 2015-06-09 17:13 jianchao-li 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Counting sort is a linear time sorting algorithm. It is used when all the numbers fall in a fixed range. Then it counts the appearances of each number... 阅读全文
posted @ 2015-06-09 15:44 jianchao-li 阅读(263) 评论(0) 推荐(0) 编辑
摘要: The hints on below the problem have suggested a two-pass solution.Now I will focus on the one-pass solution.The one-pass solution has no mystery. Just... 阅读全文
posted @ 2015-06-09 14:31 jianchao-li 阅读(196) 评论(0) 推荐(0) 编辑
摘要: This problem gets much trickier than Contains Duplicate and Contains Duplicate II.The basic idea is to maintain a window of k numbers. For each new nu... 阅读全文
posted @ 2015-06-09 11:18 jianchao-li 阅读(259) 评论(0) 推荐(0) 编辑
摘要: A classic problem of hash set. The unordered_set of C++ is very suitable for this problem.The code is as follows and it should be quite self-explanato... 阅读全文
posted @ 2015-06-09 11:01 jianchao-li 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Problem Description:Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target n... 阅读全文
posted @ 2015-06-08 23:11 jianchao-li 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(194) 评论(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 阅读(157) 评论(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 阅读(310) 评论(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 阅读(196) 评论(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 阅读(319) 评论(0) 推荐(0) 编辑