自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

_Gray

简简单单就好

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

原创 1126 Eulerian Path (25 分)

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were firs...

2019-02-26 11:24:10 139

原创 1118 Birds in Forest (25 分)

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maxi...

2019-02-26 11:22:55 121

原创 1155 Heap Paths (30 分)

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...

2019-02-25 15:32:49 141

原创 1154 Vertex Coloring (25 分)

A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k...

2019-02-25 15:31:24 114

原创 1153 Decode Registration Card of PAT (25 分)

A registration card number of PAT consists of 4 parts:the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic; the 2nd - 4th digits are the test site nu...

2019-02-25 15:30:39 100

原创 1152 Google Recruitment (20 分)

In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit p...

2019-02-25 15:29:52 140

原创 1149 Dangerous Goods Packaging (25 分)

When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂)...

2019-02-25 15:28:12 90

原创 1089 Insert or Merge (25 分)

According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...

2019-02-23 13:48:58 95

原创 1105 Spiral Matrix (25 分)

This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in...

2019-02-21 15:03:01 160

原创 1110 Complete Binary Tree (25 分)

Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line gives a positive integer N (≤20) wh...

2019-02-21 15:01:31 142

原创 1101 Quick Sort (25 分)

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its le...

2019-02-21 14:59:27 149

原创 1098 Insertion or Heap Sort (25 分)

According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...

2019-02-21 14:58:23 101

原创 1087 All Roads Lead to Rome (30 分)

Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.Input Specification:Each ...

2019-02-21 14:52:55 185

原创 1086 Tree Traversals Again (25 分)

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stac...

2019-02-21 14:51:34 330

原创 1085 Perfect Sequence (25 分)

Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respecti...

2019-02-21 14:50:26 103

原创 1082 Read Number in Chinese (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, -123456789 is read as Fu yi Yi er Qian san Bai ...

2019-02-21 14:48:37 225 1

原创 1081 Rational Sum (20 分)

Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive int...

2019-02-21 14:47:22 113

原创 1079 Total Sales of Supply Chain (25 分)

A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on th...

2019-02-21 14:45:18 128

原创 984. 不含 AAA 或 BBB 的字符串

给定两个整数 A 和 B,返回任意字符串 S,要求满足:S 的长度为 A + B,且正好包含 A 个 'a' 字母与 B 个 'b' 字母; 子串 'aaa' 没有出现在 S 中; 子串 'bbb' 没有出现在 S 中。 示例 1:输入:A = 1, B = 2输出:"abb"解释:"abb", "bab" 和 "bba" 都是正确答案。示例 2:输入:A = ...

2019-02-14 18:22:36 229

原创 11. 盛最多水的容器

给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。说明:你不能倾斜容器,且 n 的值至少为 2。图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(...

2019-02-12 18:29:53 118

原创 L3-001 凑零钱 (30 分)

韩梅梅喜欢满宇宙到处逛街。现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债。韩梅梅手边有 10​4​​ 枚来自各个星球的硬币,需要请你帮她盘算一下,是否可能精确凑出要付的款额。输入格式:输入第一行给出两个正整数:N(≤10​4​​)是硬币的总个数,M(≤10​2​​)是韩梅梅要付的款额。第二行给出 N 枚硬币的正整数面值。数字间以...

2019-02-12 01:40:08 2168

原创 991. 坏了的计算器

在显示着数字的坏计算器上,我们可以执行以下两种操作:双倍(Double):将显示屏上的数字乘 2; 递减(Decrement):将显示屏上的数字减 1 。最初,计算器显示数字 X。返回显示数字 Y 所需的最小操作数。 示例 1:输入:X = 2, Y = 3输出:2解释:先进行双倍运算,然后再进行递减运算 {2 -> 4 -> 3}.示例 2:...

2019-02-11 23:47:21 204

原创 9. 回文数

判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。示例 1:输入: 121输出: true示例 2:输入: -121输出: false解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。示例 3:输入: 10输出: false解释: 从右向左读, 为 01 。因此它不是一个回文...

2019-02-11 02:34:20 64

原创 1001 A+B Format (20 分)

Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input ...

2019-02-10 23:09:34 95

原创 打赏

2019-02-10 22:38:25 134

原创 989. 数组形式的整数加法

对于非负整数 X 而言,X 的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果 X = 1231,那么其数组形式为 [1,2,3,1]。给定非负整数 X 的数组形式 A,返回整数 X+K 的数组形式。 示例 1:输入:A = [1,2,0,0], K = 34输出:[1,2,3,4]解释:1200 + 34 = 1234解释 2:输入:A = [2,7,4...

2019-02-10 12:03:10 357

原创 986. 区间列表的交集

给定两个由一些闭区间组成的列表,每个区间列表都是成对不相交的,并且已经排序。返回这两个区间列表的交集。(形式上,闭区间 [a, b](其中 a <= b)表示实数 x 的集合,而 a <= x <= b。两个闭区间的交集是一组实数,要么为空集,要么为闭区间。例如,[1, 3] 和 [2, 4] 的交集为 [2, 3]。) 示例:输入:A = [[0,2]...

2019-02-09 16:29:32 219

原创 985. 查询后的偶数和

给出一个整数数组 A 和一个查询数组 queries。对于第 i 次查询,有 val = queries[i][0], index = queries[i][1],我们会把 val 加到 A[index] 上。然后,第 i 次查询的答案是 A中偶数值的和。(此处给定的 index = queries[i][1] 是从 0 开始的索引,每次查询都会永久修改数组 A。)返回所有查询的答案。...

2019-02-09 16:28:25 158

原创 988. 从叶结点开始的最小字符串

给定一颗根结点为 root 的二叉树,书中的每个结点都有一个从 0 到 25 的值,分别代表字母 'a' 到 'z':值 0 代表 'a',值 1 代表 'b',依此类推。找出按字典序最小的字符串,该字符串从这棵树的一个叶结点开始,到根结点结束。(小贴士:字符串中任何较短的前缀在字典序上都是较小的:例如,在字典序上 "ab" 比 "aba" 要小。叶结点是指没有子结点的结点。) 示...

2019-02-09 01:32:47 246

原创 1071 Speech Patterns (25 分)

People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker...

2019-02-04 18:41:58 108

原创 1143 Lowest Common Ancestor (30 分)

The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.A binary search tree (BST) is recursively defined as a binary tree which has ...

2019-02-04 09:40:14 146

原创 7. 整数反转

给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。示例 1:输入: 123输出: 321 示例 2:输入: -123输出: -321示例 3:输入: 120输出: 21注意:假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231,  231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。...

2019-02-03 05:55:54 69

原创 8. 字符串转换整数 (atoi)

请你来实现一个 atoi 函数,使其能将字符串转换成整数。首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可...

2019-02-03 05:49:46 72

原创 6. Z 字形变换

将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下:L C I RE T O E S I I GE D H N之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"LCIRETOESIIGEDHN"。请你实现这个将字符串进行指定行数变换的...

2019-02-02 09:19:25 139 3

原创 4. 寻找两个有序数组的中位数

给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。你可以假设 nums1 和 nums2 不会同时为空。示例 1:nums1 = [1, 3]nums2 = [2]则中位数是 2.0示例 2:nums1 = [1, 2]nums2 = [3, 4]则中...

2019-02-02 08:24:12 295

原创 3. 无重复字符的最长子串

给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。示例 1:输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。示例 2:输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。示例 3:输入: "pwwkew"输出: 3解释: 因为无重复字符的最...

2019-02-02 08:19:37 70

原创 5. 最长回文子串

给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。示例 1:输入: "babad"输出: "bab"注意: "aba" 也是一个有效答案。示例 2:输入: "cbbd"输出: "bb"动态规划解法:对每一个字符都从左右判断其是不是回文,若不是跳出循环,最后比较一下,将最大回文赋给maxstr。时间复杂度O(n2);...

2019-02-01 19:20:19 112

原创 不同路径

一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。问总共有多少条不同的路径?例如,上图是一个7 x 3 的网格。有多少可能的路径?说明:m 和 n 的值均不超过 100。示例 1:输入: m = 3, n = 2输出: 3解释:...

2019-02-01 08:29:58 101

原创 跳跃游戏

给定一个非负整数数组,你最初位于数组的第一个位置。数组中的每个元素代表你在该位置可以跳跃的最大长度。判断你是否能够到达最后一个位置。示例 1:输入: [2,3,1,1,4]输出: true解释: 从位置 0 到 1 跳 1 步, 然后跳 3 步到达最后一个位置。示例 2:输入: [3,2,1,0,4]输出: false解释: 无论怎样,你总会到达索引为 3 的...

2019-02-01 05:00:30 80

原创 1072 Gas Station (30 分)

A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the hou...

2019-01-31 18:31:05 153

空空如也

空空如也

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

TA关注的人

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