自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

码奴生来就只知道前进

在阁楼上看哲学书的孤独少年

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

原创 501. 二叉搜索树中的众数

给定一个有相同值的二叉搜索树(BST),找出 BST 中的所有众数(出现频率最高的元素)。假定 BST 有如下定义:结点左子树中所含结点的值小于等于当前结点的值 结点右子树中所含结点的值大于等于当前结点的值 左子树和右子树都是二叉搜索树 例如: 给定 BST [1,null,2,2], 1 \ 2 / 2返回[2].提示:如果众数超...

2018-07-31 23:16:47 1119

原创 563. 二叉树的坡度

给定一个二叉树,计算整个树的坡度。一个树的节点的坡度定义即为,该节点左子树的结点之和和右子树结点之和的差的绝对值。空结点的的坡度是0。整个树的坡度就是其所有节点的坡度之和。示例:输入: 1 / \ 2 3输出: 1解释: 结点的坡度 2 : 0结点的坡度 3 : 0结点的坡度 1 : |2-3| = 1树的坡...

2018-07-31 22:56:54 1003

原创 606. 根据二叉树创建字符串

你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串。空节点则用一对空括号 “()” 表示。而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。示例 1:输入: 二叉树: [1,2,3,4] 1 / \ 2 3 / 4 输出: "1(2(4))(3)"解释: 原本...

2018-07-31 22:33:39 447

原创 1008 Elevator (20)(20 分)

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 sec...

2018-07-29 18:19:07 545 3

原创 1029 Median(25 分)

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is...

2018-07-29 18:11:38 518 3

原创 543. 二叉树的直径

给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过根结点。示例 : 给定二叉树 1 / \ 2 3 / \ 4 5 返回 3, 它的长度是路径 [4,2,1,3] 或者 [5,2,1,3]。注意:两结点之间的路径长度是...

2018-07-28 22:56:02 1038 7

原创 1048 Find Coins (25)(25 分)

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...

2018-07-27 17:59:51 1025 3

原创 1041 Be Unique (20)(20 分)

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 10^4^]. The first one who bets o...

2018-07-27 17:38:16 1603 3

原创 872. 叶子相似的树

考虑一个二叉树的所有叶子。这些叶子的值按从左到右的顺序排列形成一个 叶值序列 。举个例子,给定一个如上图所示的树,其叶值序列为 (6, 7, 4, 9, 8) 。如果两个二叉树的叶值序列相同,我们就认为它们是 叶相似的。如果给定的两个头结点分别为 root1 和 root2 的树是叶相似的,返回 true;否则返回 false 。提示:给定的两个树会有 1 到 100 个结...

2018-07-26 22:20:04 487

原创 541. 反转字符串 II

给定一个字符串和一个整数 k,你需要对从字符串开头算起的每个 2k 个字符的前k个字符进行反转。如果剩余少于 k 个字符,则将剩余的所有全部反转。如果有小于 2k 但大于或等于 k 个字符,则反转前 k 个字符,并将剩余的字符保持原样。示例:输入: s = "abcdefg", k = 2输出: "bacdfeg"要求:该字符串只包含小写的英文字母。 给定字符串的长度和 k...

2018-07-26 22:05:31 116

原创 538. 把二叉搜索树转换为累加树

给定一个二叉搜索树(Binary Search Tree),把它转换成为累加树(Greater Tree),使得每个节点的值是原来的节点值加上所有大于它的节点值之和。例如:输入: 二叉搜索树: 5 / \ 2 13输出: 转换为累加树: 18 / ...

2018-07-26 21:41:27 139

原创 530. 二叉搜索树的最小绝对差

给定一个所有节点为非负值的二叉搜索树,求树中任意两节点的差的绝对值的最小值。示例 :输入: 1 \ 3 / 2输出:1解释: 最小绝对差为1,其中 2 和 1 的差的绝对值为 1(或者 2 和 3)。 注意: 树中至少有2个节点。分析:二叉搜索树的中序遍历为升序序列,因此问题就转化为这个生序序列相邻两个值的差的最小值。/**...

2018-07-26 21:29:56 749

原创 521. 最长特殊序列 Ⅰ

给定两个字符串,你需要从这两个字符串中找出最长的特殊序列。最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列)。子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序。空序列为所有字符串的子序列,任何字符串为其自身的子序列。输入为两个字符串,输出最长特殊序列的长度。如果不存在,则返回 -1。示例 :输入: "aba", "cdc"...

2018-07-26 21:01:39 346

原创 506. 相对名次

给出 N 名运动员的成绩,找出他们的相对名次并授予前三名对应的奖牌。前三名运动员将会被分别授予 “金牌”,“银牌” 和“ 铜牌”(”Gold Medal”, “Silver Medal”, “Bronze Medal”)。(注:分数越高的选手,排名越靠前。)示例 1:输入: [5, 4, 3, 2, 1]输出: ["Gold Medal", "Silver Medal", "Br...

2018-07-26 20:49:30 519

原创 463. 岛屿的周长

给定一个包含 0 和 1 的二维网格地图,其中 1 表示陆地 0 表示水域。网格中的格子水平和垂直方向相连(对角线方向不相连)。整个网格被水完全包围,但其中恰好有一个岛屿(或者说,一个或多个表示陆地的格子相连组成的岛屿)。岛屿中没有“湖”(“湖” 指水域在岛屿内部且不和岛屿周围的水相连)。格子是边长为 1 的正方形。网格为长方形,且宽度和高度均不超过 100 。计算这个岛屿的周长。示例 :...

2018-07-26 20:07:38 773

原创 1075 PAT Judge (25)(25 分)

The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT.Input Specification:Each input file co...

2018-07-26 11:48:40 619

原创 1028 List Sorting (25)(25 分)

1028 List Sorting (25)(25 分) Excel can sort records according to any column. Now you are supposed to imitate this function.InputEach input file contains one test case. For each case, the first li...

2018-07-23 11:27:03 622

原创 458. 可怜的小猪

有1000只水桶,其中有且只有一桶装的含有毒药,其余装的都是水。它们从外观看起来都一样。如果小猪喝了毒药,它会在15分钟内死去。问题来了,如果需要你在一小时内,弄清楚哪只水桶含有毒药,你最少需要多少只猪?回答这个问题,并为下列的进阶问题编写一个通用算法。进阶:假设有 n 只水桶,猪饮水中毒后会在 m 分钟内死亡,你需要多少猪(x)就能在 p 分钟内找出“有毒”水桶?n只水桶里有且仅...

2018-07-22 18:29:14 1263

原创 438. 找到字符串中所有字母异位词

给定一个字符串 s 和一个非空字符串 p,找到 s 中所有是 p 的字母异位词的子串,返回这些子串的起始索引。字符串只包含小写英文字母,并且字符串 s 和 p 的长度都不超过 20100。说明:字母异位词指字母相同,但排列不同的字符串。 不考虑答案输出的顺序。 示例 1:输入:s: "cbaebabacd" p: "abc"输出:[0, 6]解释: 起始索引等...

2018-07-22 18:10:50 693

原创 437. 路径总和 III

给定一个二叉树,它的每个结点都存放着一个整数值。找出路径和等于给定数值的路径总数。路径不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点到子节点)。二叉树不超过1000个节点,且节点数值范围是 [-1000000,1000000] 的整数。示例:root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8...

2018-07-22 17:28:38 433

原创 1082 Read Number in Chinese (25)(25 分)

1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output “Fu” first if it is negative. For example, -1234...

2018-07-22 12:19:09 489

原创 1077 Kuchiguse (20)(20 分)

1077 Kuchiguse (20)(20 分) The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. S...

2018-07-22 11:59:58 658

原创 1035 Password (20)(20 分)

1035 Password (20)(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to dist...

2018-07-22 11:42:49 977

原创 1005 Spell It Right (20)(20 分)

1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input ...

2018-07-22 11:14:43 1376

原创 1027 Colors in Mars (20)(20 分)

1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digi...

2018-07-21 14:01:52 397

原创 1019 General Palindromic Number (20)(20 分)

1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All ...

2018-07-21 13:48:24 666

原创 74. 搜索二维矩阵

编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:每行中的整数从左到右按升序排列。 每行的第一个整数大于前一行的最后一个整数。 示例 1:输入:matrix = [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50]]target = 3输出: true示例 2:...

2018-07-20 23:54:08 592

原创 832. 翻转图像

给定一个二进制矩阵 A,我们想先水平翻转图像,然后反转图像并返回结果。水平翻转图片就是将图片的每一行都进行翻转,即逆序。例如,水平翻转 [1, 1, 0] 的结果是 [0, 1, 1]。反转图片的意思是图片中的 0 全部被 1 替换, 1 全部被 0 替换。例如,反转 [0, 1, 1] 的结果是 [1, 0, 0]。示例 1:输入: [[1,1,0],[1,0,1],[0,0...

2018-07-20 23:18:58 323

原创 696. 计数二进制子串

给定一个字符串 s,计算具有相同数量0和1的非空(连续)子字符串的数量,并且这些子字符串中的所有0和所有1都是组合在一起的。重复出现的子串要计算它们出现的次数。示例 1 :输入: "00110011"输出: 6解释: 有6个子串具有相同数量的连续1和0:“0011”,“01”,“1100”,“10”,“0011” 和 “01”。请注意,一些重复出现的子串要计算它们出现的次数...

2018-07-20 22:58:05 383

原创 1036 Boys vs Girls (25)(25 分)

1036 Boys vs Girls (25)(25 分) This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:...

2018-07-20 15:35:15 315

原创 1006 Sign In and Sign Out (25)(25 分)

1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the ...

2018-07-20 15:18:07 341

原创 1011 World Cup Betting (20)(20 分)

1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the W...

2018-07-20 14:38:34 427

原创 1009 Product of Polynomials (25)(25 分)

1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 l...

2018-07-20 14:27:26 1055

原创 1065 A+B and C (64bit) (20)(20 分)

1065 A+B and C (64bit) (20)(20 分) Given three integers A, B and C in [-2^63^, 2^63^], you are supposed to tell whether A+B > C.Input Specification:The first line of the input gives the positiv...

2018-07-19 21:34:54 632

原创 1046 Shortest Distance (20)(20 分)

1046 Shortest Distance (20)(20 分) The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Sp...

2018-07-19 21:08:04 402 1

原创 572. 另一个树的子树

给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。示例 1: 给定的树 s: 3 / \ 4 5 / \ 1 2给定的树 t: 4 / \ 1 2返回 true,因为 t 与 s 的一个子树拥有相同的...

2018-07-19 18:38:48 345

原创 709. 转换成小写字母

实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。示例 1:输入: "Hello"输出: "hello"示例 2:输入: "here"输出: "here"示例 3:输入: "LOVELY"输出: "lovely"class Solution {public:

2018-07-19 18:18:59 1343

原创 653. 两数之和 IV - 输入 BST

给定一个二叉搜索树和一个目标结果,如果 BST 中存在两个元素且它们的和等于给定的目标结果,则返回 true。案例 1:输入: 5 / \ 3 6 / \ \2 4 7Target = 9输出: True案例 2:输入: 5 / \ 3 6 / \ \2 4 7Target = 28...

2018-07-19 18:11:37 121

原创 804. 唯一摩尔斯密码词

国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: “a” 对应 “.-“, “b” 对应 “-…”, “c” 对应 “-.-.”, 等等。为了方便,所有26个英文字母对应摩尔斯密码表如下:[“.-“,”-…”,”-.-.”,”-..”,”.”,”..-.”,”–.”,”….”,”..”,”.—”,”-.-“,”.-..”,”–”,”-.”,”—...

2018-07-19 17:27:39 584

原创 1042 Shuffling Machine (20)(20 分)

1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where...

2018-07-19 13:22:52 1449 1

空空如也

空空如也

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

TA关注的人

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