自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(424)
  • 资源 (1)
  • 收藏
  • 关注

原创 clockwise print binary search tree

给一个二叉树, 顺时针打印出所有的节点, 例如:应该打印: 20, 8, 4, 10, 14, 25, 22思路: 可以分为三步打印:1. 打印左边界, 最后一个叶子节点不打印2. 打印所有叶子结点3. 打印右边界, 根和最后一个叶子结点不打印代码如下: void printLeft(TreeNode* root){ if(

2016-12-10 14:47:11 879

原创 [leetcode] 412. Fizz Buzz 解题报告

题目链接: https://leetcode.com/problems/fizz-buzz/Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the

2016-12-01 15:57:15 1045

原创 [leetcode] 437. Path Sum III 解题报告

题目链接: https://leetcode.com/problems/path-sum-iii/You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does

2016-12-01 15:45:27 1468

原创 [leetcode] 450. Delete Node in a BST 解题报告

题目链接: https://leetcode.com/problems/delete-node-in-a-bst/Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly u

2016-12-01 15:24:38 3383

原创 [leetcode] 422. Valid Word Square 解题报告

题目链接: https://leetcode.com/problems/valid-word-square/Given a sequence of words, check whether it forms a valid word square.A sequence of words forms a valid word square if the kth row and c

2016-12-01 15:05:19 1633

原创 [leetcode] 421. Maximum XOR of Two Numbers in an Array 解题报告

题目链接: https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR

2016-12-01 10:49:34 1135

原创 [leetcode] 462. Minimum Moves to Equal Array Elements II 解题报告

题目链接: https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a

2016-11-30 15:43:53 1565

原创 数组建堆(heapify)

将一个数组调整为最大堆. 根据堆的性质, 只要保证部分有序即可, 即根节点大于左右节点的值. 将数组抽象为一个完全二叉树, 所以只要从最后一个非叶子节点向前遍历每一个节点即可. 如果当前节点比左右子树节点都大, 则已经是一个最大堆, 否则将当前节点与左右节点较大的一个交换, 并且交换过之后依然要递归的查看子节点是否满足堆的性质, 不满足再往下调整. 如此即可完成数组的堆化.

2016-11-27 08:52:54 16929 1

原创 [leetcode] 463. Island Perimeter 解题报告

题目链接: https://leetcode.com/problems/island-perimeter/You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connecte

2016-11-25 12:34:35 3621 1

原创 一些常见面试OO design题目总结

最近很多公司面试喜欢问一些OO design的题目, 我总结了一些比较高频的题目, 需求不一定准确, 设计的也不一定好, 欢迎提出建议. 1. 电梯设计 2. 停车厂设计 3. 通用卡牌游戏blackjack设计 4...1. 电梯设计需求:

2016-11-24 06:09:52 17477 2

原创 [leetcode] 447. Number of Boomerangs 解题报告

题目链接: https://leetcode.com/problems/number-of-boomerangs/Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between

2016-11-23 12:12:19 1645

原创 [leetcode] 455. Assign Cookies 解题报告

题目链接:https://leetcode.com/problems/assign-cookies/Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i h

2016-11-21 09:34:10 720

原创 [leetcode] 454. 4Sum II 解题报告

题目链接:https://leetcode.com/problems/4sum-ii/Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make

2016-11-21 08:54:49 1962 2

原创 求数组最大递增子串

题目描述: 给定一个数组, 对于每一个位置向前找不大于该位置的最长序列长度, 返回最长的一个序列长度, 该位置之前的序列不需要连续增长, 只要小于当前位置值即可. 例如: [1, 4, 2, 6], length[0] = 1, length[1] = 2, length[2] = 1, length[3] = 4.思路: 利用一个栈维护一个递减序列, 也就是如果当前元素小于栈顶元

2016-11-17 12:07:37 596

原创 两个有序数组求第k小元素

和两个数组求中位数有点类似. 思路还是二分查找, 也就是在一个数组中进行二分搜索, 每次比较中点位置元素和另一个数组对应位置的大小关系. 比如要找第K个数, 并且当前搜索到了数组A的x位置, 那么要比较的B数组中的位置应该为(k-x-1), 也就是使得数组A中到索引x的元素个数+B中到(k-x-2)索引的元素个数之和为k, 也就是:A:   x            x+1B:   k-x

2016-11-17 10:56:18 2144 1

原创 手把手教你scrapy + mongodb 爬虫爬取GooglePlay

这几天折腾了一个分布式爬虫,我自己也是刚开始学,查了很多资料,现在终于可以动了,我觉得应该发文纪念一下,也是一个总结.scrapy是一个python的爬虫框架,可以让你很快的开发出一个爬虫,首先假定你已经安装了python, 你还需要安装一下scrapy,可以用pip来安装:1. install Python-pip: sudo apt-get install python-pip2.

2016-11-15 03:43:25 6383 1

原创 [leetcode] 453. Minimum Moves to Equal Array Elements 解题报告

题目链接:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, wh

2016-11-11 06:47:59 1010

原创 [leetcode] 451. Sort Characters By Frequency 解题报告

题目链接:https://leetcode.com/problems/sort-characters-by-frequency/Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Ex

2016-11-11 05:40:30 4228

原创 [leetcode] 449. Serialize and Deserialize BST 解题报告

题目链接:https://leetcode.com/problems/serialize-and-deserialize-bst/Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file

2016-11-08 03:05:55 3134

原创 [leetcode] 414. Third Maximum Number 解题报告

题目链接:https://leetcode.com/problems/third-maximum-number/Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The t

2016-10-26 23:43:22 2033

原创 [leetcode] 438. Find All Anagrams in a String 解题报告

题目链接:https://leetcode.com/problems/find-all-anagrams-in-a-string/Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase Engl

2016-10-26 22:46:39 3514

原创 [leetcode] 418. Sentence Screen Fitting 解题报告

xxx: https://leetcode.com/problems/sentence-screen-fitting/Given a rows x cols screen and a sentence represented by a list of words, findhow many times the given sentence can be fitted on the

2016-10-14 07:25:27 6801

原创 [leetcode] 416. Partition Equal Subset Sum 解题报告

题目链接:https://leetcode.com/problems/partition-equal-subset-sum/Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum o

2016-10-10 04:43:26 6599

原创 [leetcode] 415. Add Strings 解题报告

题目链接:https://leetcode.com/problems/add-strings/Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2

2016-10-10 04:16:05 1519

原创 [leetcode] 409. Longest Palindrome 解题报告

题目链接:https://leetcode.com/problems/longest-palindrome/Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those let

2016-10-10 04:01:48 953

原创 [leetcode] 408. Valid Word Abbreviation 解题报告

题目链接:https://leetcode.com/problems/valid-word-abbreviation/Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation.A string such

2016-10-10 03:48:20 3108

原创 [leetcode] 404. Sum of Left Leaves 解题报告

题目链接:https://leetcode.com/problems/sum-of-left-leaves/Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leave

2016-10-10 03:23:03 908

原创 [leetcode] 396. Rotate Function 解题报告

题目链接:https://leetcode.com/problems/rotate-function/Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise,

2016-10-09 09:15:28 545

原创 c++在用set和multiset时遇到的一个bug

今天在写一个程序时用到了set和multiset,因为我需要让其中的元素对降序排列,所以写了一个functor,为图省事,我只比较了pair中首个元素如下:struct cmp{ bool operator()(pair a, pair b) { return a.first > b.first; }};然后噩梦就开始了!刚开始我用的是set, 在我往se

2016-10-03 13:53:51 510

原创 [leetcode] 406. Queue Reconstruction by Height 解题报告

题目链接:https://leetcode.com/problems/queue-reconstruction-by-height/Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), where h is

2016-09-29 09:57:33 5879 1

原创 [leetcode] 407. Trapping Rain Water II 解题报告

题目链接:https://leetcode.com/problems/trapping-rain-water-ii/Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of wate

2016-09-29 06:25:11 5821 3

原创 数组中两个元素异或求最大值

给一个整数数组,求数组中两个元素异或的最大值.思路:naive的做法是两两异或求最大值,时间复杂度为O(n*n),但是还有一种O(n)的解法,利用字典树Trie来实现.其思路是利用数组中的每个元素二进制表示形式建一棵树,我看到网上大多数解法都开了太大的数组空间,不知道为什么,但是我觉得没有必要.只要用现有的数组元素二进制值建一棵深度为33的树即可,从根到叶子结点的路径就代表了一个元

2016-09-28 22:56:57 7051 1

原创 [leetcode] 397. Integer Replacement 解题报告

题目链接:https://leetcode.com/problems/integer-replacement/Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with

2016-09-19 13:25:56 1058

原创 [leetcode] 398. Random Pick Index 解题报告

题目链接:https://leetcode.com/problems/random-pick-index/Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target

2016-09-19 13:17:13 1874

原创 [leetcode] 402. Remove K Digits 解题报告

题目链接:https://leetcode.com/problems/remove-k-digits/Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.N

2016-09-19 11:50:18 6387

原创 [leetcode] 401. Binary Watch 解题报告

题目链接:https://leetcode.com/problems/binary-watch/A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED repr

2016-09-19 09:45:37 3633

原创 [leetcode] 400. Nth Digit 解题报告

题目链接:https://leetcode.com/problems/nth-digit/Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:n is positive and will fit within the range of a

2016-09-19 08:54:28 5426

原创 [leetcode] 399. Evaluate Division 解题报告

题目链接:https://leetcode.com/problems/evaluate-division/Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point num

2016-09-17 05:05:21 3467

原创 [leetcode] 392. Is Subsequence 解题报告

题目链接:https://leetcode.com/problems/is-subsequence/Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t

2016-09-09 14:49:15 2410

原创 [leetcode] 393. UTF-8 Validation 解题报告

题目链接:https://leetcode.com/problems/utf-8-validation/A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:For 1-byte character, the first bit is a 0, followed b

2016-09-09 08:54:54 2486

qt3扫雷代码

本程序制作精心,代码完整,为10*10大小的雷区,等级分为三级,简单,中等,困难。其中布雷使用随机数生成,扫空格使用广度搜索BFS,基本具备了扫雷的应有的功能。界面友善,希望能对你有帮助。

2013-11-15

空空如也

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

TA关注的人

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