- 博客(13)
- 资源 (6)
- 收藏
- 关注
原创 深度优先+回溯法生成随机迷宫
如题,迷宫效果:#include #include #include #include "time.h"#include "stdlib.h"using namespace std;class MazeCell {public: bool right, down; bool visited; int x, y; MazeCell() : x(0), y(
2013-11-13 14:04:55 1489
原创 C++ 并查集模板:找矩阵中'0'区域的个数
#include "time.h"#include #include #include using namespace std;template class UnionFind {private: map parent;public: void Union(T x, T y) { map::iterator i; T px = Find(x); T py = F
2013-10-22 08:08:12 1686
原创 C++ LRU Cache
#include #include #include using namespace std;template class LRUNode {public: Key key; Value value; class LRUNode *prev, *next; LRUNode() : prev(NULL), next(NULL) {} LRUNode(Key k, Value
2013-10-20 16:38:56 972
原创 [GeeksforGeeks]Remove all adjacent duplicates
Given a string, recursively remove adjacent duplicate characters from string. The output string should not have any adjacent duplicates.Input: azxxzyOutput: ayFirst "azxxzy" is reduced to "az
2013-10-17 13:20:41 2917
原创 [LeetCode]String to Integer
class Solution {public: int atoi(const char *str) { // Note: The Solution object is instantiated only once and is reused by each test case./* * input: space, sign, digits, int limit */
2013-10-11 02:52:59 824
原创 自己编写的80x86虚拟机 NXVM
发一款自己写的80x86虚拟机 NXVM【简介】这个虚拟机是用C编写的,一共37,000行代码。它完整的模拟了一台PC,包括一个80386 CPU,以及所有必要的设备,例如内存、DMA、中断控制器、软驱、硬盘、键盘、显示器等。因此,它可以运行一个基于x86的操作系统,如MS-DOS6.22。NXVM虚拟机可以同时在Windows和Linux下通过编译。在Wind
2013-10-10 04:15:57 6248 3
原创 [LeetCode]Reverse Integer
这题啥也不说了,简单…… 记一下代码。要通过测试,主要就是处理一下正负号。class Solution {public: int reverse(int x) { // Note: The Solution object is instantiated only once and is reused by each test case.
2013-10-10 02:39:48 753
原创 [LeetCode]ZigZag Conversion
这题没什么意思,就是纯粹的找规律。发现所有行的重复周期都是 2 * nRows - 2对于首行和末行之间的行,还会额外重复一次,重复的这一次距离本周期起始字符的距离是 2 * nRows - 2 - 2 * iclass Solution {public: string convert(string s, int nRows) { // Start
2013-10-09 15:01:22 5721 2
原创 [LeetCode]Longest Palindromic Substring
Longest Palindromic Substring此题用Manacher算法解答,时间O(n),空间O(n).首先在字符串的首尾,以及每个字符之间加上'#',形成新字符串s1,这样可以统一处理子串为奇数或偶数的情况。我们用一个数组p来保存s1字符串中以每个字符为中心时,左右对称扩展的最大值,即以该字符为中心时的最大对称长度。例如:#a#b#b#a#,最中间的'#'的p值为4。接着我们扫描所
2013-10-09 14:09:54 1276
原创 [LeetCode]Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *ad
2013-10-09 00:06:50 1117
原创 [LeetCode]Longest Substring Without Repeating Characters
此题用一个hash table保存每个字符上一次出现过的位置。从前往后扫描,假如发现字符上次出现过,就把当前子串的起始位置start移动到上次出现过的位置之后。同时,由于start移动,当前子串的内容改变,start移动过程中经历的字符都要剔除。class Solution {public: int lengthOfLongestSubstring(string s) {
2013-10-08 14:51:33 2882 1
原创 [LeetCode]Median of Two Sorted Arrays
Median of Two Sorted Arrays这题挺难的,边界条件老是考虑不清楚。所以在这里记录一下思路,免得将来忘记。There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time
2013-10-08 14:17:59 1205 1
原创 [LeetCode]Two Sum
Two Sum这题思路很简单,创建一个hash table,用来存放访问过的数值和对应的位置。从头到尾循环,假如hash table里面有匹配的数值,则取出对应的数值的位置并直接返回。Given an array of integers, find two numbers such that they add up to a specific target number.The f
2013-10-08 13:36:06 1605
自己编写的80386虚拟机NXVM
2013-10-18
BMP图像读写、格式转换、处理函数
2012-04-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人