- 博客(190)
- 收藏
- 关注
原创 [leetcode][Binary Search] First Bad Version
题目:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed bas
2015-09-11 09:06:31
555
原创 [leetcode][Binary Search] H-Index II
题目:Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint:Expected runtime complexity is in O(log n) and the input is s
2015-09-06 15:38:42
575
原创 [leetcode][sort] H-Index
题目:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h-index on Wikip
2015-09-04 20:07:42
527
原创 [leetcode][单调性] 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
2015-08-25 15:55:04
351
原创 [leetcode][贪心] 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
2015-08-24 12:02:48
520
原创 [leetcode][math] Missing Number
题目:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algori
2015-08-24 10:48:48
375
原创 [leetcode][string] Longest Palindromic Substring
题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Manacher算法(
2015-08-19 16:28:18
289
原创 [leetcode][dp] Ugly Number II
Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first
2015-08-19 11:23:19
406
原创 [leetcode][math] Ugly Number
题目:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is no
2015-08-19 11:21:42
447
原创 [leetcode] Number of Islands
题目:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You
2015-08-18 18:43:59
262
原创 内存泄露检测
1.vs2013(1)#define CRTDBG_MAP_ALLOC(2)#if DEBUG#ifdef _DEBUG#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)注:用于定位哪一行发生内存泄漏(3)在入口函数的结束处添加 _CrtDumpMemoryLeaks();(4)F5运行,即可在输出窗口看到内存泄
2015-08-18 14:40:59
381
原创 [leetcode][trie] Implement Trie (Prefix Tree)
题目:Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode {public: // Initialize your da
2015-08-18 13:56:07
318
原创 [leetcode][two pointers] Minimum Size Subarray Sum
题目:Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the a
2015-08-18 10:00:27
322
原创 [leetcode][位运算] Single Number III
题目:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:
2015-08-17 17:42:47
916
原创 [leetcode][deque] Sliding Window Maximum
题目:Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding
2015-08-17 17:15:45
346
原创 [leetcode][stack] Implement Queue using Stacks
题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front eleme
2015-08-17 09:21:54
304
原创 [leetcode][math] Add Digits
题目: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: 3 + 8 = 11, 1 + 1 = 2. Since 2
2015-08-16 14:31:55
787
原创 [leetcode][tree] Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/**
2015-08-16 13:34:50
879
2
原创 [leetcode][dfs] Different Ways to Add Parentheses
题目:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.Examp
2015-08-15 15:37:41
321
原创 [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
441
原创 [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
350
转载 数组中只出现一次的数
首先看看题目要求:数组A中,除了某一个数字x之外,其他数字都出现了三次,而x出现了一次。请给出最快的方法找到x。 这个题目非常有意思,在本人博客中有《位操作基础篇之位操作全面总结》这篇文章介绍了使用位操作的异或来解决——数组中其他数字出现二次,而x出现一次,找出x。有《【白话经典算法系列之十二】数组中只出现1次的两个数字(百度面试题)》这边文章介绍了分组异或的方法来解决——
2015-07-12 19:45:51
323
原创 [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
305
转载 回调函数
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
318
原创 [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
243
原创 [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
298
原创 [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
299
原创 [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
305
原创 [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
343
原创 [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
244
原创 [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
274
原创 [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
263
原创 [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
282
原创 [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
311
原创 C++实现单例模式
class Singleton{ //其他成员private: Singleton(){ cout << "Hello Singleton!" << endl; }//私有构造函数 Singleton(const Singleton &);//拷贝构造函数,只声明不定义,这要当用户或友元想要拷贝构造该类的已存在实例时会出错。 Singleton & operator= (const S
2015-07-03 14:37:53
261
原创 sleep()、yield()和wait()
注:以下函数都是指Java中的函数sleep()使当前线程(即调用该方法的线程)暂停执行一段时间(用户可以指定暂停多久),让其他线程有机会继续执行。要点:1.进入阻塞状态2.不释放锁。3.可以使低优先级的线程、同优先级的线程、高优先级的线程都有执行的机会。4.可以抛出 InterruptionException 异常yield()同sleep()
2015-07-02 21:06:16
275
原创 孤儿进程和僵尸进程
1.孤儿进程一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养,并由init进程对它们完成状态收集工作。此时,init进程将以父进程的身份对这些孤儿进程进行处理。孤儿进程没什么危害2.僵尸进程一个进程使用fork创建子进程,如果子进程退出,而父进程并没有调用wait或waitpid获取子进程的状态信息,那么
2015-07-02 19:25:50
414
转载 [Http] cookie和session
Session简介摘要:虽然session机制在web应用程序中被采用已经很长时间了,但是仍然有很多人不清楚session机制的本质,以至不能正确的应用这一技术。本文将详细讨论session的工作机制并且对在Java web application中应用session机制时常见的问题作出解答。 目录: 一、术语session 二、HTTP协议与状态保持 三、理解cook
2015-07-02 19:04:05
403
原创 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
339
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人