
LeetCode
CourageK
计算所
展开
-
Single Number
题意:Given an array of integers, every element appears twice except for one. Find that single one.要求:线性时间复杂度,并且不用额外空间。Logic: XOR will return 1 only on two different bits. So if two numbers are t转载 2014-09-21 20:41:58 · 670 阅读 · 0 评论 -
「动态规划」Palindrome Partitioning II
/************************************************************************* > File Name: PalindromePartitioningII.cpp > Author: Shaojie Kang > Mail: kangshaojie@ict.ac.cn > Created Time: 2015年09月1原创 2015-09-16 17:55:50 · 425 阅读 · 0 评论 -
Related Problems
1.“高效地安排面试”扩展问题一:某一天,在微软亚洲研究院有N个面试要进行,它们的时间分别为(B[i], E[i])(B[i]为面试开始时间,E[i]为面试结束时间)。假设一个面试者一天只参加一个面试。为了给面试者提供一个安静便于发挥的环境,我们希望将这N个面试安排在若干个面试点。不同的面试在同一个时间不能被安排在同一个面试点。如果你是微软亚洲研究院的HR,现在给定这N个面试的时间之后,你原创 2015-08-03 08:29:06 · 8590 阅读 · 0 评论 -
用memset对非字符型数组初始化可能会出现错误
功能:memset是对一个一个的字节进行初始化。有可能出错的地方: 如果对int数组进行初始化为非0的整数,会出现错误,如:memset(arr, 1, sizeof(int)*length)每个数都被初始化为00000001 00000001 00000001 00000001。而不是1#include#include#include#includeusing namespace原创 2015-05-18 14:26:47 · 934 阅读 · 0 评论 -
Remove Element的两种解法
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2015-05-12 20:51:15 · 3080 阅读 · 0 评论 -
Leetcode题目分类:类型+难易
=== 十月十五日更 ===题已刷完,这篇总结还落下不少进度。这个网站本属于个人博客,以后我不想把刷题这种纯找工作的文章发在这里。另外,我回头审视了以前写的一些题解,发现还有不少提升空间,包括对解法的描述和代码的优化。因此我重新做了一个题解网站,也希望能以更加清晰的分类目录和解法帮助读者提升刷题的效率,早点从刷题中走出来,做些更有意思的事。鉴于我需要重新描述大多数题目的解法,新的网站目前只转载 2015-04-15 16:16:48 · 3947 阅读 · 0 评论 -
LRUCache
struct cacheNode{ int key; int value; cacheNode(int k,int v):key(k),value(v){}};class LRUCache{private: int capacity; list cacheList; unordered_map::iterator> cacheMap;p原创 2015-04-15 15:52:29 · 577 阅读 · 0 评论 -
Validate Binary Search Tree
1.测试用例没有考虑INT_MIN,以至于一开始采用INT_MIN作为最小值。Solution:采用is_first变量,以存储第一个值;2.单独用递归程序写时,容易导致很多错误,并不能真正验证是否是一个合格的二叉排序树。比如,右子树中的某个节点大小有可能小于该节点的值,这样的二叉树就不是二杈排序树。错误代码如下://bool isValidBST(TreeNode *root)//原创 2015-04-12 16:28:14 · 410 阅读 · 0 评论 -
Leetcode:Combinations
1.ProblemGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1原创 2015-03-12 21:41:29 · 465 阅读 · 0 评论 -
Evaluate Reverse Polish Notation
1.ProblemEvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples:原创 2015-03-10 21:57:34 · 509 阅读 · 0 评论 -
Divide Two Integers
1.ProblemDivide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.2.Pre-Thought既然题目中要求不可以用乘法、除法和求余运算符,那么只能用加法和减法来求商了。(暂且没有想到用bit来解题的思路)原创 2015-03-09 21:41:03 · 601 阅读 · 0 评论 -
Valid Number
Problem:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a ca原创 2014-10-20 13:38:56 · 582 阅读 · 0 评论 -
Longest Common Prefix
Problem:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a ca原创 2014-10-20 16:12:47 · 491 阅读 · 0 评论 -
Valid Palindrome
Problem:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a ca原创 2014-10-13 21:29:53 · 544 阅读 · 0 评论 -
「回溯法」Palindrome Partitioning
/************************************************************************* > File Name: PalindromePartitioning.cpp > Author: Shaojie Kang > Mail: kangshaojie@ict.ac.cn > Created Time: 2015年09月16日原创 2015-09-16 16:58:23 · 413 阅读 · 0 评论