随笔分类 - 做题
摘要:插入排序: 插入排序,幻想成是你在抓扑克牌的时候。以i为分割线,i之前的扑克牌都是已经拍好顺序的了。 所以你需要在i进行插入的时候,和它前面的一个个比较,若前面的要大于它,就覆盖,直到找到一个小于它的数j,就放在这个数的后面。 插入排序可以高速整理顺序很整齐的数据。 冒泡排序 从高处开始,往底层两个
阅读全文
摘要:地址: http://lintcode.com/zh-cn/problem/binary-tree-level-order-traversal/ 借助队列来完成 http://lintcode.com/zh-cn/problem/binary-tree-level-order-traversal-i
阅读全文
摘要:地址: http://lintcode.com/zh-cn/problem/subsets/ http://lintcode.com/zh-cn/problem/subsets-ii/ 子集 其实就是一颗子集树 带重复元素的子集 筛选一下分支,排序数组,然后相同的元素只能出现1,...,0...或者
阅读全文
摘要:lintcode地址: http://lintcode.com/zh-cn/problem/permutations/ http://lintcode.com/zh-cn/problem/permutations-ii/ 全排列,用了子集树的解法: 带重复元素的排列 筛选条件就是在i和t不等的时候,
阅读全文
摘要:这个题目也是挺简单的,不过这里用到了对vector的排序。 会发现是直接传入开头和结尾的,然后进一步去了解一下其中的原理: vector采用的数据结构很简单:线性的连续空间。 它以两个迭代器start和finish分别指向配置得来的连续空间中目前已经被使用的空间。迭代器end_of_storage指
阅读全文
摘要:这个题目的思想是,肯定要有一个结构来保存最小值。 起初我想的是可以只用一个数就能保存最小值吗,显然不太可能,因为我们只能访问栈顶获得数据。 那么就用第二个栈来保存这个最小 数据,又是不是不用保存多个数据,在每次弹出压入的时候就把数据整理好?也不太可能,因为在数据出栈的时候,那相应min堆栈里的也要出
阅读全文
摘要:给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符。 a和b都是 32位 整数。 肯定是用位操作符号来实现,那就要推算一下过程,数位和进位位。 0+0=0 0+1=1 1+0=1 1+1=0 所以a^b是没有进位的时候得到的数位。 而只有在1+1的时候会产生进位,所以a&b是进位的结果
阅读全文
摘要:这个题,说实话我是好难想出来<-_<-,后来看了别人的思路才发现原来是理解为。 当对方要拿的时候,石头还剩下4个,那这个时候他拿几个,剩下的你都能一次拿了,也就是你赢了。 所以就要凑一个自己拿完的时候,刚好还剩下4个,也就是除以4要有余数,所以就有了答案。
阅读全文
摘要:693是一道很简单的题目。
阅读全文
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g
阅读全文
摘要:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number
阅读全文
摘要:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like:
阅读全文
摘要:Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202" Example 2: Input: -7 Output: "-10" Note: The input will
阅读全文
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of
阅读全文
摘要:The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "on
阅读全文
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. var merg
阅读全文
摘要:Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you
阅读全文
摘要:今天真是郁闷啊( ̄﹏ ̄;),写了好几个题目都未果(难道是因为中午一直在上课吗?) Given a sorted array, remove the duplicates in place such that each element appear only once and return the n
阅读全文
摘要:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpo
阅读全文