自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Clairezz_的博客

Never give up!

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

原创 [leetcode][dfs] Binary Tree Maximum Path Sum

题目:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Ret

2015-07-16 20:38:34 437

原创 [leetcode][array] Product of Array Except Self

题目:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division

2015-07-16 15:11:07 343

转载 数组中只出现一次的数

首先看看题目要求:数组A中,除了某一个数字x之外,其他数字都出现了三次,而x出现了一次。请给出最快的方法找到x。 这个题目非常有意思,在本人博客中有《位操作基础篇之位操作全面总结》这篇文章介绍了使用位操作的异或来解决——数组中其他数字出现二次,而x出现一次,找出x。有《【白话经典算法系列之十二】数组中只出现1次的两个数字(百度面试题)》这边文章介绍了分组异或的方法来解决——

2015-07-12 19:45:51 315

原创 [leetcode][dfs] Lowest Common Ancestor of a Binary Search Tree

题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defin

2015-07-12 12:53:06 303

转载 回调函数

void printHello(int n){//相应回调事件 printf("你好---%d\n", n);}void printBye(int n){ printf("再见---%d\n", n);}void caller(int n, void(*print)(int)){//相应回调事件 int sum = 0; for (int i = 1; i <= n; ++i){

2015-07-10 21:41:29 316

原创 [leetcode][list] Palindrome Linked List

题目:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked list. * struct ListNode { *

2015-07-10 10:12:49 239

原创 [leetcode][hash] Contains Duplicate III

题目:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between

2015-07-08 16:22:19 294

原创 [leetcode][hash] Contains Duplicate II

题目:Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at

2015-07-08 15:46:06 294

原创 [leetcode][回溯] Combination Sum III

题目:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that n

2015-07-08 15:16:10 239

原创 [leetcode][list] Add Two Numbers

题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it

2015-07-07 17:01:27 297

原创 [leetcode][list] Remove Duplicates from Sorted List II

题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi

2015-07-07 11:22:55 340

原创 [leetcode][list] Remove Duplicates from Sorted List

题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definitio

2015-07-07 10:17:49 243

原创 [leetcode][list] Reorder List

题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reord

2015-07-06 16:32:28 264

原创 [leetcode][list] 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.Note:Given m, n 

2015-07-06 15:51:05 261

原创 [leetcode][math][bit] Power of Two

题目:Given an integer, write a function to determine if it is a power of two.思路一:强解,如果一个数是2的n次方,那么它一定只有1和2两约数。注意:这里用移位运算">>"代替除法运算"/"使效率更高。 class Solution {public: bool isPowerOfTwo(int n)

2015-07-06 09:47:04 280

原创 [leetcode][DP][回溯] Word Break II

题目:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, giv

2015-07-03 18:16:51 308

原创 C++实现单例模式

class Singleton{ //其他成员private: Singleton(){ cout << "Hello Singleton!" << endl; }//私有构造函数 Singleton(const Singleton &);//拷贝构造函数,只声明不定义,这要当用户或友元想要拷贝构造该类的已存在实例时会出错。 Singleton & operator= (const S

2015-07-03 14:37:53 260

原创 sleep()、yield()和wait()

注:以下函数都是指Java中的函数sleep()使当前线程(即调用该方法的线程)暂停执行一段时间(用户可以指定暂停多久),让其他线程有机会继续执行。要点:1.进入阻塞状态2.不释放锁。3.可以使低优先级的线程、同优先级的线程、高优先级的线程都有执行的机会。4.可以抛出 InterruptionException 异常yield()同sleep()

2015-07-02 21:06:16 274

原创 孤儿进程和僵尸进程

1.孤儿进程一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养,并由init进程对它们完成状态收集工作。此时,init进程将以父进程的身份对这些孤儿进程进行处理。孤儿进程没什么危害2.僵尸进程一个进程使用fork创建子进程,如果子进程退出,而父进程并没有调用wait或waitpid获取子进程的状态信息,那么

2015-07-02 19:25:50 410

转载 [Http] cookie和session

Session简介摘要:虽然session机制在web应用程序中被采用已经很长时间了,但是仍然有很多人不清楚session机制的本质,以至不能正确的应用这一技术。本文将详细讨论session的工作机制并且对在Java web application中应用session机制时常见的问题作出解答。 目录: 一、术语session 二、HTTP协议与状态保持 三、理解cook

2015-07-02 19:04:05 401

原创 git

1.检出仓库git clone username@host:/path/to/repository2.添加与提交git add   -------从工作目录添加到缓冲区git commit -m "改动信息"  ------将改动提交到本地仓库的HEADgit push origin master   ------将改动提交到远程仓库的master或任何分支

2015-07-02 18:03:20 335

原创 正则表达式

第一行 #!/bin/sh 表示脚本的解释器程序的路径^ 匹配字符串的开始$ 匹配字符串的结束$0 当前程序的名称,实际上是一个内部参数,不同于$1,$2....因为它必须有!$# 传递给程序的总的参数数目,也就是那个传说中的数组大小$*  传递给程序的所有参数组成的字符串。$@  以"参数1" "参数2" ... 形式保存所有参数通

2015-07-02 17:14:55 287

转载 静态重定位与动态重定位

程序和数据装入内存时需对目标程序中的地址进行修改。这种把逻辑地址转变为内存的物理地址的过程叫重定位。对程序进行重定位的技术按重定位的时机可分为两种:静态重定位和动态重定位。1.静态重定位静态重定位是在目标程序装入内存时,由装入程序对目标程序中的指令和数据的地址进行修改,即把程序的逻辑地址都改成实际的地址。对每个程序来说,这种地址变换只是在装入时一次完成,在程序运行期间不再进行重定位

2015-07-02 16:49:26 9751

原创 [leetcode][BST] Recover Binary Search Tree

题目:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could

2015-07-02 13:13:12 225

原创 [leetcode][桶排序] Maximum Gap

题目;Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2

2015-07-02 11:35:38 393

原创 [leetcode][BST] Kth Smallest Element in a BST

题目:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:Wh

2015-07-02 09:32:03 284

转载 堆栈帧及其布局

从逻辑上讲进程的堆栈是由多个堆栈帧构成的,其中每个堆栈帧都对应一个函数调用。当函数调用发生时,新的堆栈帧被压入堆栈;当函数返回时,相应的堆栈帧从堆栈中弹出。尽管堆栈帧结构的引入为在高级语言中实现函数或过程这样的概念提供了直接的硬件支持,但是由于将函数返回地址这样的重要数据保存在程序员可见的堆栈中,因此也给系统安全带来了极大的隐患。

2015-07-01 21:26:32 547

原创 [MOS学习笔记] 完成系统调用read的11个步骤

注:1.C和C++编译器使用逆序,即第一个参数放在堆栈顶部2.库过程是由汇编语言写成的。因为引发系统调用的实际机制是非常依赖于机器的,一些诸如保存寄存器值和设置堆栈指针之类的操作是无法用C语言这一高级语言描述,所以这些操作通过一个短小的汇编语言例程来完成,使得C语言(或其他语言)能够通过调用该例程来使用系统调用。3.陷入内核(TRAP)和普通的过程调用有什么不同?1)执行普通的过程

2015-07-01 20:24:28 992

原创 为什么要区分用户态和内核态?

在CPU的所有指令中,有些指令是非常危险的,如果错用,将导致系统崩溃,比如清内存、设置时钟等。如果所有的程序都能使用这些指令,那么系统死机的概率将大大增加。所以,CPU将指令分为特权指令和非特权指令,对于那些危险的指令,只允许操作系统及其相关模块使用,普通应用程序只能使用那些不会造成灾难的指令。Intel的CPU将特权等级分为4个级别:Ring0~Ring3Linux使用Ring3

2015-07-01 19:55:02 5629

原创 自由软件、开源软件、免费软件、共享软件和商业软件

商业软件:将软件作为商品进行交易,即付费才能使用自由软件和开源软件都意味着将软件的可执行文件和源码免费提供给用户,而且用户可以使用、复制、修改和发行(分发)该软件。但是自由软件走得更远一些,它的原则是:你可以“自由”地运行、拷贝、修改和在发行使用GPL授权的软件,但是你也必须允许别人能“自由”地运行、拷贝、修改和再发行该软件以及你在该软件基础上加以修改而形成的衍生软件产品。而开源软件是

2015-07-01 19:37:01 2723

转载 进程切换

其过程的基本思想是:当进程A要切换出去时,先把EIP和其他寄存器的内容保存到自己的堆栈中,而这个被保存的EIP实际指向了用来恢复其他寄存器的指令的起始地址。接着将ESP的内容保存到对应的thread_struct结构体中(我的理解是此结构体相当于PCB中的一部分)以备切换回来时使用。在ESP中装入进程B的ESP内容,其他需要切换回来的状态分量都可以通过ESP切换回来,注意按照保存的顺序切换回来

2015-07-01 17:08:53 831

原创 什么是进程表?

进程表,也称进程控制块(PCB),是由操作系统维护的,每个进程占用其中一个表项。该表项包含了操作系统对进程进行描述和控制的全部信息,从而保证该进程换出后再次启动时,就像从未中断过一样。在典型的系统中包含如下关键字段;1.进程管理相关包含三大类信息;1)标识信息:用于唯一地标识一个进程,包括进程ID、父进程、进程组等。2)现场信息:用于保留一个进程在运行时存放在处理器现场中的各种

2015-07-01 16:51:42 4911

原创 [leetcode][math] Sqrt(x)

题目:Implement int sqrt(int x).Compute and return the square root of x.思路一:从1开始逐步逼近 ———可以accept但是效率很低class Solution {public:int mySqrt(int x) { if (x < 0) return -1; if (x <= 1) return

2015-07-01 12:25:11 358

原创 [leetcode][DP] Palindrome Partitioning II

题目;Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab"

2015-07-01 11:12:33 258

空空如也

空空如也

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

TA关注的人

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