代码改变世界

interview problems

2018-01-11 10:52 by 明星bigdata, 153 阅读, 0 推荐, 收藏, 编辑
摘要:2018.1.10.1 Eat Cheese I 房间里有多块奶酪(x,y),小老鼠一开始在(0,0),问小老鼠吃掉所有奶酪要走的最短距离。dfs + 剪枝。 #include <iostream> #include <vector> #include <math.h> #include <limi 阅读全文

lintcode bugfree and good codestyle note

2016-12-04 00:23 by 明星bigdata, 167 阅读, 0 推荐, 收藏, 编辑
摘要:2016.12.4, 366 http://www.lintcode.com/en/problem/fibonacci/ 一刷使用递归算法,超时。二刷使用九章算术的算法,就是滚动指针的思路,以前写python的时候也玩过,但是给忘了,这次又用c++拾起来了。lint有bug,不能用,很烦。 clas 阅读全文

leetcode bugfree note

2016-11-30 19:33 by 明星bigdata, 596 阅读, 0 推荐, 收藏, 编辑
摘要:463. Island Perimeterhttps://leetcode.com/problems/island-perimeter/就是逐一遍历所有的cell,用分离的cell总的的边数减去重叠的边的数目即可。在查找重叠的边的数目的时候有一点小技巧,就是沿着其中两个方向就好,这种题目都有类似的规 阅读全文

leetcode 419

2016-11-06 12:45 by 明星bigdata, 486 阅读, 0 推荐, 收藏, 编辑
摘要:题目说明: Given an 2D board, count how many different battleships are in it. The battleships are represented with 'X's, empty slots are represented with ' 阅读全文

leetcode 165

2016-10-25 19:22 by 明星bigdata, 189 阅读, 0 推荐, 收藏, 编辑
摘要:才一周没刷leetcode,手就生了,这个题目不难,但是完全AC还是挺费劲的。 题目描述: Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 < version 阅读全文

leetcode 155

2016-10-08 09:25 by 明星bigdata, 151 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- 阅读全文

leetcode 204

2016-10-05 00:19 by 明星bigdata, 192 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述: Description: Count the number of prime numbers less than a non-negative number, n. 解法一: 遍历从1-n的所有整数,查看是否为质数,是质数借助一个则将该整数存入一个容器中,判断一个数是否为质数,可以遍历在 阅读全文

leetcode 28

2016-10-03 14:31 by 明星bigdata, 160 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 分析: 这个题目考察的是KMP算法, 阅读全文

将二叉搜索树转为有序双向链表

2016-09-28 09:58 by 明星bigdata, 652 阅读, 0 推荐, 收藏, 编辑
摘要:部分转载自http://blog.csdn.net/sgbfblog/article/details/7939589 题目描述 给定一棵二叉排序树(BST),将该树转换成一棵双向循环链表。请看下面的图示说明,你可以更清楚的了解题意。 BST的结构定义如下: 图1)一棵存储1-5的二叉搜索树(BST) 阅读全文

leetcode 397

2016-09-26 17:13 by 明星bigdata, 336 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述: Given a positive integer n and you can do operations as follow: What is the minimum number of replacements needed for n to become 1? Example 1: 阅读全文