自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

hzj的博客

学习+找工作笔记

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

原创 49.leetcode题目18. 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:

2016-05-30 14:36:38 304

原创 48.leetcode题目17. Letter Combinations of a Phone Number

(好久不记录,但其实一直有缓慢的做,坚持不放弃,纯当记录一下思路,下次要边做题边写,每次做完题再来写就没感觉了。)题目:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (jus

2016-05-24 22:44:28 326

原创 6.关联容器

前言:今天下午接到了百度的电话面试,被虐得体无完肤。。所以立马决定刷题。正文:set容器是STL中的关联容器,是基于红黑树的。set作为一个容器也是用来存储同一数据类型的数据类型,并且能从一个数据集合中取出数据,在set中每个元素的值都唯一,而且系统能根据元素的值自动进行排序。

2016-05-08 19:19:46 346

原创 47.leetcode题目2. Add Two Numbers

class Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *result=NULL,*next,*temp;//ListNode *result,*next,*temp;未通过编译 ListNode *l11=l1,*l22=l2;

2016-05-03 14:29:32 235

原创 46.leetcode题目:94. Binary Tree Inorder Traversal

题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursiv

2016-04-19 18:15:06 236

原创 45.leetcode题目:144. Binary Tree Preorder Traversal

题目:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursi

2016-04-17 18:42:54 215

原创 44.leetcode题目:268. 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

2016-04-17 17:12:00 325

原创 43.leetcode题目:319. Bulb Switcher

题目;There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or tur

2016-04-17 16:48:13 253

原创 42.leetcode题目:169. Majority Element(还有一种方法待做)

题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority

2016-04-15 13:38:36 302

原创 41.leetcode题目217. Contains Duplicate(哈希方法还没做)

题目:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every ele

2016-04-14 21:13:37 231

原创 40.leetcode题目:

这两天在刷leetcode上的动态规划题目,昨天大概刷了三题,但是没有记录博客,因为下周要做报告,所以最近比较忙,故过段时间再添上。我还是希望自己能够坚持下去,仿佛这就意味着我人生的一大步——坚持!!今天的题目有:96:unique binary search tree309. Best Time to Buy and Sell Stock with Cooldown这

2016-04-06 13:19:42 255

转载 5.动态规划

一、基本概念    动态规划的过程是:每次决策依赖于当前状态,又随机引起状态的转移。    动态规划算法通常都是基于一个递推公式及一个或多个初始状态。当前子问题的解由上一次子问题的解推出。使用动态规划解题只需要多项式时间复杂度,因此比回溯法、暴力法等要快。二、示例     注:原文转载自:动态规划:从新手到专家March 26, 2013作者:H

2016-04-03 16:10:09 842

原创 39.leetcode题目121、 122、 123

121题:动态规划Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share

2016-04-02 21:14:05 328

原创 38.leetcode题目231:231. Power of Two

题目:Given an integer, write a function to determine if it is a power of two.分析:判断是否是2的整数次幂。class Solution {public: bool isPowerOfTwo(int n) { if(n<=0) return false;

2016-04-02 16:23:56 222

原创 37.leetcode题目191: Number of 1 Bits

题目:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representati

2016-04-02 15:51:30 258

原创 36.leetcode题目338: Counting Bits(再做一遍)

题目:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:Fo

2016-04-02 15:24:18 236

原创 35.leetcode题目100: Same Tree

题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.分析:

2016-04-02 14:02:21 222

原创 34.leetcode题目260: 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:

2016-04-02 12:26:38 206

原创 33.leetcode题目237: Delete Node in a Linked List

题目:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node w

2016-04-02 11:05:26 192

原创 32.leetcode题目283: Move Zeroes

题目:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after ca

2016-04-01 14:41:44 195

原创 31.leetcode题目226: Invert Binary Tree

题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1分析:递归调用class Solution {public: TreeNode* invertTree(Tre

2016-04-01 13:52:45 187

原创 30.leetcode题目104: Maximum Depth of Binary Tree(递归,深度优先)

题目:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.分析:要深刻理解树的结构定义是一个递归的定义,

2016-03-30 13:18:51 244

原创 29.leetcode题目258: 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

2016-03-30 12:56:56 291

原创 28.leetcode题目292: Nim Game

题目:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone wi

2016-03-30 12:24:10 432

原创 27.leetcode题目137: Single Number II(考察位操作)

题目:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it wi

2016-03-29 23:24:08 264

原创 26.leetcode题目136: Single Number

题目:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without

2016-03-29 16:27:28 188

原创 25.leetcode题目190: Reverse Bits(Follow up未解决)

题目:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0

2016-03-27 19:50:58 463

原创 24.leetcode题目20: Valid Parentheses

前言:这道题目在《数据结构》这本书上有讲,学习真的很重要啊!题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correc

2016-03-23 22:38:56 208

原创 23.leetcode题目203: Remove Linked List Elements(待再做)

题目:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5分析:方法一:用一个新指针Li

2016-03-17 20:58:54 187

原创 22.leetcode题目206: Reverse Linked List

题目:Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?分析:翻转链表。根据提示:方法一,依次翻转c

2016-03-16 21:04:16 232

原创 21.leetcode题目234: Palindrome Linked List(第2种方法是链表翻转,等做完206题再做!)

题目: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?分析:方法1:将链表里的数据都提出来放在vector里,然后循环vector作比较,判断是否是回文。这是一种很直接的方法。链表结束的时

2016-03-16 19:58:37 245

原创 20.leetcode题目67: Add Binary

题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".分析:二进制加法,用数组或者字符串class Solution {public: string addBinary(string

2016-03-16 19:33:32 235

原创 19.leetcode题目303: Range Sum Query - Immutable

题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) ->

2016-03-15 19:06:35 175

原创 18.leetcode题目28: Implement strStr()

题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.寻找needle在haystack中出现的位置。一个个比较呗。class Solution {publi

2016-03-15 19:00:07 169

原创 4.线程和进程

关于进程和线程描述正确的是()正确答案: A B D   你的答案: A B C D (错误)线程不拥有系统资源,但可以访问隶属于进程的资源在创建或销毁进程时,系统开销明显大于创建或销毁线程时开销进程是调度和拥有资源的基本单位不仅进程可以并发执行,同一个进程的多个线程之间也可以并发执行线程作为调度和分配的基本单位,进程

2016-03-15 15:51:13 363

原创 3.Linux中fork()函数

一个进程,包括代码、数据和分配给进程的资源。fork()函数通过系统调用创建一个与原来进程(父进程)几乎完全相同的进程(子进程),这两个进程共享代码空间,但数据空间是独立的,子进程数据空间中的内容是父进程的完整拷贝,指令指针也完全相同,但只有一点不同,fork调用的一个奇妙之处就是它仅仅被调用一次,却能够返回两次,如果fork成功,子进程中fork的返回值是0,父进程中fork的返回值是子进程的进

2016-03-15 15:12:35 429

原创 2.堆和栈

注::基本是网上查找的答案heap堆:是由malloc和new之类函数分配的空间所在地,由程序员分配和释放,若程序员不释放,程序结束时可能由os回收。地址是由低向高增长的。heap的空间是很大的自由区。 stack栈:是自动分配变量,以及函数调用的时候所使用的一些空间,存放函数的参数值,局部变量值等。地址是由高向低减少的。 stack空间有限。全局区(静态区)(static):

2016-03-14 19:39:10 216

原创 17.leetcode题目204: Count Primes(不是最快的!)

前言:这道题目一开始觉得挺简单的,编写一个判断每一个数是否是质数的函数isPrime: bool isPrime(int m){ if(m<=1){ return false; } for(int i=2;i<m/2;i++){ //根据 hint 2修改 for(int i=2;i<=sqrt(m);i++){ //根据 hint 3修改 if(m%i==0){ return false; }

2016-03-14 16:32:34 204

原创 1.学习1: 埃拉托色尼筛选法(求一定范围内的质数)

前言:这是在刷leetcode第204题: Count Primes时hint提示的。埃拉托色尼选筛法(the Sieve of Eratosthenes)简称埃氏筛法,是古希腊数学家埃拉托色尼(Eratosthenes 274B.C.~194B.C.)提出的一种筛选法。 是针对自然数列中的自然数而实施的,用于求一定范围内的质数,它的容斥原理之完备性条件是p=H~。

2016-03-14 15:21:41 1365

原创 16.leetcode题目228: Summary Ranges

题目:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].分析:第一个问题,为什么所有测试用例都没有判断降序的情况?题目只是说已经排序的数组而已,

2016-03-14 12:30:23 187

空空如也

空空如也

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

TA关注的人

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