自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

LUCKYOJ

https://github.com/lucky521

  • 博客(58)
  • 收藏
  • 关注

原创 通配符匹配字符串 Wildcard Matching

问题:实现支持?和*两个通配符的字符串匹配函数。Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).

2014-03-31 22:09:34 2424 2

原创 Linux文件系统中的inode索引结点 VFS inode

Linux中VFS文件系统的组织当我们读取一个文件时,实际上是在目录中找到了这个文件的inode编号,然后根据inode的指针,把硬盘中数据块组合起来,放入内存供进一步的处理。当我们写入一个文件时,是分配一个空闲inode给该文件,将其inode编号记入该文件所属的目录,然后选取空闲的数据块,让inode的指针指向这些数据块,并放入内存中的数据。硬盘扇区 sector

2014-03-31 15:22:17 3570

原创 Cache的设计和实现 LRU Cache

Cache的应用非常广泛,其实Cache是一种思想,一个广义的词汇,一种在性能和金钱的权衡上的思想。Cache的思想用在很多地方,使用的载体也不同,都是位于相对高速设备和相对低速设备之间,起到缓存的作用。1、最常用处:用在内存和CPU之间,以SRAM作为Cache的载体。(内存是DRAM,CPU是寄存器)2、用在内存和硬盘之间。3、用在硬盘和网络之间。

2014-03-31 09:52:26 2654

原创 被包围的棋子 Surrounded Regions

问题:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O XX

2014-03-30 19:22:57 9325 5

原创 文本布局调整 Text Justification

问题:Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach;

2014-03-30 17:28:29 1391

原创 变形字符串识别 Scramble String

问题:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \

2014-03-27 19:51:42 1675

原创 Leetcode题:Substring with Concatenation of All Words

You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an

2014-03-26 21:23:50 5905

原创 Java Servlet 开发实践

本篇说的是最基础的Java Web开发,也就是纯Servlet,不包含框架、JSP。Servlet类库是J2EE中最重要的部分其,主要的接口有:Filter FilterChain FilterConfig RequestDispatcher Servlet ServletConfig ServletContext ServletContextAtt

2014-03-26 15:27:31 903

原创 Github 简明用法

如今越来越多的开源项目托管在Github上面,不会用怎么可以呢。本文是一份简明的用法。首先是要对这台机器做配置。第一步:注册账户。注册是免费的并且过程非常简单。注册之后就可以直接在浏览器上编写和管理代码。第三步:在本机上装上git客户端,这样才能和github服务器端保持同步。$ sudo apt-get install git-gui第三步:添加一个SSH

2014-03-25 17:15:29 961

原创 Phaser - HTML5开源游戏框架

这是一个有趣的开源游戏框架,地址在https://github.com/photonstorm/phaserPhaser是一个JavaScript游戏框架,用于开发2D网页游戏。借助这个游戏框架,我们可以把精力集中在游戏设计上、非常迅速的开发出想要炫酷游戏。提供全套的物理特性和Sprites,API非常简单,内部同时使用了 Canvas and WebGL,同时支持移动浏览器和桌面

2014-03-24 22:32:56 1635

原创 寻找排列数中的第k个数 Permutation Sequence

问题:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""2

2014-03-24 21:11:32 2245

原创 计算逆波兰式 Evaluate Reverse Polish Notation

问题:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2",

2014-03-24 09:54:05 1685

原创 我对Java Servlet的认识

Servlet是Server applet的合成词。它是把Java语言编写的类使用在服务器上,服务于服务器的功能。与其等价的竞争对手是PHP、ASP.NET。从狭义的编程角度来讲,Servlet是Java的一个API,使用它就可以开发服务器程序,程序中有许多个处理WEB请求的Servlet类。从广义上讲,按照Sun公司要求的这样一种开发规则所写出的WEB项目,就是Java Servlet。

2014-03-23 17:25:20 1169

原创 找出较大的下一个数字组合 Next Permutation

问题:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possi

2014-03-22 18:51:31 1963

原创 回文子串划分 Palindrome Partitioning

问题:将一个字符串进行划分,要求划分成的子串都必须是回文串。找出所有可能的划分情况。思路:backstrack吧,每一次只有在满足是回文的情况下深入下一层。class Solution {public: vector> partition(string s) { vector > result; vector now; if(s.s

2014-03-21 19:21:53 1481

原创 生成所有可能的二叉排序树 Unique Binary Search Trees II

问题:Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1

2014-03-21 12:39:21 1270

原创 对Linux内存地址转换、保护模式的理解

相关概念:实模式、保护模式、GDT、LDT、物理地址、逻辑地址、线性地址(虚拟地址)实模式Intel 80286时代使用的模式。访问內存是通过segment:offset找到內存的。即“左移4位加偏移”,segment保护模式如今大部分的x86操作系都在保护模式下运行。内存的管理模式分为两种,段模式和页模式访问一个内存地址仍然使用Se

2014-03-21 11:17:34 1777

原创 找出穿过最多点的直线 Max Points on a Line

平面上有若干个点,要你找出一条直线,使其能穿过最多的点。思路:枚举法。求出任意两点之间的线,以直线(斜率,与y轴的交点坐标)的形式存储到map。这样个数最多的直线就是所求。时间O(N^2),空间O(N).注意特殊情况:1、当直线的斜率为无穷大时,其与y轴没有交点,但是和x轴的交点不相同,这时候我需要特殊表示一下。2、点集中有重叠的点时,算几个点?

2014-03-20 21:34:52 6170 2

原创 截取浮点数的小数位数

对于一个double a = 1.234567;如果我只取小数点后3位,那么我可以这样做:a = floor(a*1000)/1000;floor函数的作用是返回一个小于传入参数的最大整数,所以对于正数来说,就是抹去小数点后的部分。它具有多种形式:double floor (      double x );  float floor (       float x );

2014-03-20 17:26:17 12490

原创 有障碍物的矩阵格路径的个数 Unique Paths II

在《矩形格路径的个数 Unique Paths》中,介绍了求解矩阵格路径个数的两种方法,这种属于没有阻碍的路径个数。本文要处理的问题是,如果人为的在矩阵的某些格子中布置障碍物,意味着不能通过该格子。那么格路径的个数如何求解。思路:该问题仍然具有子问题。还是可以采用动态规划方法。设置状态量H[][],H[i][j]表示从A[0][0]格子到A[i][j]格子的路径个数。递推关系:

2014-03-20 13:14:01 3060

原创 数组中,有三个数只出现1次,其他都出现2次,找出来那三个数。 3 Unique

问题:数组中,有三个数只出现1次,其他都出现2次。找出来那三个数。注意:由于3是奇数,所以这三个数都相同的位异或起来也会是1。思路:假设将数组中所有数异或起来之后。假如某一位为0,说明所求那三个数在这一位是000或者110. 假如某一位为1,说明所求那三个数在这一位是100或者111.因此根据这个异或结果没办法找出一个位进行有效的分组。

2014-03-20 10:23:56 2007

原创 僵尸进程和孤儿进程的比较

在Unix类系统中,这两类进程非常常见。一种叫Zombie,一种叫Orphan。由于名字的关系,容易混淆。Unix的进程关系的机制:    unix提供了一种机制可以保证只要父进程想知道子进程结束时的状态信息,就可以得到。    在每个进程退出的时候,内核释放该进程所有的资源,包括打开的文件,占用的内存等。但是仍然为其保留一定的信息(包括进程号the process ID,退出状态th

2014-03-19 16:07:36 1589

原创 简单的限定个数组合生成 Combinations

问题:Given 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,3

2014-03-19 13:23:43 1048

原创 找出数组中和为指定值的四个数 4sum

问题:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:

2014-03-18 22:13:02 1368

原创 解码方法数 Decode Ways

问题:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total

2014-03-17 21:10:07 1777

原创 Find subarray with given sum

问题:Given an unsorted array of integers, find a continous subarray which adds to a given number.注意:数组中有正有负。参见:http://stackoverflow.com/questions/5534063/zero-sum-subarray#include#include#in

2014-03-17 20:37:29 823

原创 字符串单词拆分 Word Break

问题:给出一个字符串,问能否将其拆分为1或多个单词。单词表已给出。Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, given

2014-03-17 10:07:28 3458

原创 Candy

问题:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at l

2014-03-16 20:03:45 1217

原创 根据中序和后序序列重建二叉树 Construct Binary Tree from Inorder and Postorder Traversal

问题:Given inorder and postorder traversal of a tree, construct the binary tree.参考:根据前序序列和中序序列重建二叉树,http://blog.csdn.net/ojshilu/article/details/11855167,两个问题如出一辙。注意:下面程序并没有做严格的合法性检查。1、递归时两个序列长度总是

2014-03-15 12:58:13 1156

原创 字母矩形中单词搜索 Word Search

问题:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertica

2014-03-14 19:47:28 1393

原创 寻找最少次跳数 - 贪心VS动态规划 Jump Game 2

非常好的问题:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your

2014-03-14 12:35:44 4483

原创 附有随机结点指针的链表的深度拷贝 Copy List with Random Pointer

问题:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.思路:目前想到的办法是借助hash保存旧结点到

2014-03-13 18:27:36 1702

原创 把一个文件创建为文件系统

在Linux系统中,可以把一个文件创建为文件系统,然后挂载到操作系统上。这就成为文件系统中的一个文件系统。可以起来封装隔离或者加密保护的作用。1、创建一个指定大小的全空文件$ dd if=/dev/zero of=file.img bs=1k count=100002、把文件关联成一个循环设备$ losetup /dev/loop0 file.img3、将该循环设备创

2014-03-13 15:20:13 1242 1

原创 逆转链表的一部分 Reverse Linked List II

问题:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.特殊输入:m=n,即逆转的部分只有一

2014-03-13 10:22:02 1188

原创 链表的二路归并排序 Sort List

对于链表,想找一种时间复杂度为O(nlogn),空间复杂度O(1)的算法。Sort a linked list in O(n log n) time using constant space complexity.首先想到了归并排序,因为链表的归并不需要辅助空间。思路:和数组的二路归并基本一致。所不同的是:1、要遍历一遍才能找到中间位置。2、首尾位置都要记下来,因为链表不是

2014-03-12 13:43:57 2912 1

原创 合并时间段 Merge Intervals

问题:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].思路:注意特殊情况:1、start点有重合。 2、end点有重合。  3、一个start和一个

2014-03-12 10:33:42 1719

原创 字符串中某子序列的个数 Distinct Subsequences

问题:Given a string S and a string T, count the number of distinct subsequences of T in S.要求出S中所有的为T的子序列。思路:一、直观想法:递归试探。指数级复杂度。class Solution {public: int numDistinct(string S, string T)

2014-03-11 19:36:55 2389

原创 链表的插入排序 Insertion Sort List

使用插入排序算法对单链表进行排序。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {publi

2014-03-11 18:40:32 1233

原创 Remove Duplicates from Sorted Array II

问题:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2

2014-03-10 19:56:28 835

原创 生成N皇后问题所有局面 N-Queens

Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("ba

2014-03-10 19:25:17 973

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除