自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Valid Perfect Square

Given a positive integer num, write a function which returns True if num is a perfect square else False.注意事项Do not use any built-in library function such as sqrt.样例 For example: Given num = 1

2018-01-29 16:02:58 147

原创 对称数II

对称数是一个旋转180度后(倒过来)看起来与原数相同的数.找到所有长度为 n 的对称数.样例: 给出 n = 2 返回 [“11”,”69”,”88”,”96”].思路: 利用递归求解,给出n=1时,结果为{0,1,8}, n=2时,结果为{11,69,88,96} 计算n时,就先计算n-2(此时的n-2包括以0开头的字符串) 再将n=2的结果,分别加到n-2结果的两边。#i

2018-01-29 15:24:09 1812

原创 Calculate Maximum Value II -LintCode

Given a string of numbers, write a function to find the maximum value from the string, you can add a + or * sign between any two numbers,It’s different with Calculate Maximum Value, You can insert par

2018-01-26 11:16:47 354

原创 最小子数组

给定一个整数数组,找到一个具有最小和的子数组。返回其最小和。注意事项子数组最少包含一个数字样例 给出数组[1, -1, -2, 1],返回 -3思路: 令sum表示当前所取子数组的和,ans表示最小和。遍历数组,将元素加到sum上,利用sum更新ans。若sum>0,则重新开始取数组,令sum=0。#ifndef C44_H#define C44_H#include

2018-01-26 09:30:42 472

原创 John's business

There are n cities on an axis, numbers from 0 ~ n - 1. John intends to do business in these n cities, He is interested in Armani’s shipment. Each city has a price for these goods prices [i]. For city

2018-01-25 15:33:00 271

原创 Group Anagrams

Given an array of strings, group anagrams together.注意事项All inputs will be in lower-case.样例Given strs = ["eat", "tea", "tan", "ate", "nat", "bat"],Return [ ["ate", "eat","tea"], ["

2018-01-23 15:13:47 124

原创 Repeated DNA

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T. For example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Writ

2018-01-23 14:24:04 168

原创 John's backyard garden

John wants to build a back garden on the empty space behind his home. There are two kinds of bricks now, one is 3 dm high and the other is 7 dm high. John wants to enclose a high x dm wall. If John ca

2018-01-23 11:24:54 277

原创 132 模式 -LintCode

给你一个 n 个整数的序列 a1,a2,…,an,一个 132 模式是对于一个子串 ai,aj,ak,满足 i < j < k 和 ai < ak < aj。设计一个算法来检查输入的这 n 个整数的序列中是否存在132模式。 n 会小于 20,000。样例: 给你序列 nums = [1,2,3,4] 返回 False//没有132模式在这个序列中。 给你序列 nums = [3,1,4,

2018-01-16 09:31:08 553

原创 Smallest Subset-LintCode

Given an array of non-negative integers. Our task is to find minimum number of elements such that their sum should be greater than the sum of rest of the elements of the array.样例: Given nums = [3, 1,

2018-01-15 15:02:03 251

原创 Palindromic Ranges-LintCode

A positive integer is a palindrome if its decimal representation (without leading zeros) is a palindromic string (a string that reads the same forwards and backwards). For example, the numbers 5, 77, 3

2018-01-15 14:45:45 870

原创 Balance Graph-LintCode

Given a directed graph where each edge is represented by a tuple, such as [u, v, w]represents an edge with a weight w from u to v. You need to calculate at least the need to add the number of edges to

2018-01-11 20:30:31 493

原创 不同的路径 III-LintCode

“不同的路径II”的 follow up:http://lintcode.com/en/problem/unique-paths-ii/ 现在每一个格子都包含了一个值,所以每条路径都有一个值,找到所有值不同的路径的和样例: 举个例子,[ [1,1,2], [1,2,3], [3,2,4]]这里有两条值不同的路径: [1,1,2,3,4] = 11 [1,1,2,2,4] = 1

2018-01-08 20:04:47 370

原创 折叠数组-LintCode

给一个长度为 n 的数组 nums 和一个长度为 k 的数组 req, 你需要根据要求折叠数组,并输出折叠的结果 1.如果 req[i] = 0 意味着你应该从左到右折叠, 例如:1 2 3 4 5 6 7 8 ==> 4 3 2 1 5 6 7 82.如果 req[i] = 1 意味着你应该从右往左折叠, 例如:1 2 3 4 5 6 7 8

2018-01-08 16:12:45 1544

原创 平面范围求和 -不可变矩阵-LintCode

给一 二维矩阵,计算由左上角 (row1, col1) 和右下角 (row2, col2) 划定的矩形内元素和.注意事项: 你可以假设矩阵不变 对函数 sumRegion 的调用次数有很多次 你可以假设 row1 ≤ row2 并且 col1 ≤ col2样例: 给出矩阵[ [3, 0, 1, 4, 2], [5, 6, 3, 2, 1], [1, 2, 0, 1, 5],

2018-01-06 09:53:40 228

原创 最大子数组VI-LintCode

给出一个整数数组,找出异或值最大的子数组。 什么是异或:https://en.wikipedia.org/wiki/Exclusive_or注意事项: 预期时间复杂度为O(n)样例: 给出nums = [1, 2, 3, 4],返回 7,子数组[3, 4]有最大的异或值 给出nums = [8, 1, 2, 12, 7, 6],返回 15,子数组[1, 2, 12]有最大的异或值 给出nu

2018-01-04 21:48:12 578

原创 下一个稀疏数-LintCode

一个数是稀疏数如果这个数的 二进制表示 中没有相邻的 1,给出一个 n ,找出大于或等于 n 的最小的稀疏数。 eg. 5 (二进制表示为 101)是稀疏数,但是 6 (二进制表示为 110 )不是稀疏数样例: 给出 n = 6,返回 8下一个稀疏数是8 给出 n = 4,返回 4下一个稀疏数是4 给出 n = 38,返回 40下一个稀疏数是40 给出 n = 44,返回 64下一个稀疏数

2018-01-03 14:39:55 317

原创 Monotone Increasing Digits-LintCode

Given a non-negative integer N, find the largest number that is less than or equal to N with monotone increasing digits.(Recall that an integer has monotone increasing digits if and only if each pair o

2018-01-02 14:44:35 215

原创 Boolean Parenthesization-LintCode

Given a boolean expression with following symbols.Symbols 'T' ---> true 'F' ---> false And following operators filled between symbolsOperators & ---> boolean AND | ---> boolean OR

2017-12-30 16:10:29 385

原创 中国剩余定理-LintCode

给出两个数组 num[0..k - 1] 和 rem[0..k - 1]. 在数组num[0..k - 1]中, 所有的元素都是互质的( gcd 为 1 ). 我们需要找到满足下列条件的最小正数 x: x % num[0] = rem[0], x % num[1] = rem[1], ....................... x % n

2017-12-27 16:27:40 709

原创 Sum of first K even-length Palindrome numbers-LintCode

Given a integer k, find the sum of first k even-length palindrome numbers. Even length here refers to the number of digits of a number is even.样例Given k = 3, return 66 // 11 + 22 + 33 = 66 (Sum of fir

2017-12-26 17:03:03 181

原创 滑动窗口内唯一元素数量和-LintCode

给一个数组和一个滑动窗口的大小, 求每一个窗口内唯一元素的个数和样例:给一个数组 nums = [1, 2, 1, 3, 3] 和 k = 3第一个窗口为 [1, 2, 1], 只有 2 是唯一的, 计数为 1.第二个窗口为 [2, 1, 3], 所有的元素都是唯一的, 计数为 3.第三个窗口为 [1, 3, 3], 只有 1 是唯一的, 计数为 1.总数为 1 + 3 + 1 = 5返

2017-12-26 16:20:36 521

原创 Compute 24 Game-LintCode

You have 4 cards each containing a number from 1 to 9. You need to compute whether they could operated through *, /, +, -, (, ) to get the value of 24.注意事项The division operator / represents real divis

2017-12-25 17:07:19 323

原创 Count Different Palindromic Subsequences-LintCode

Given a string S, find the number of different non-empty palindromic subsequences in S, and return that number modulo 10^9 + 7. A subsequence of a string S is obtained by deleting 0 or more characters

2017-12-25 10:14:25 239

原创 正则表达式匹配-LintCode

Implement regular expression matching with support for ‘.’ and ‘*’.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string

2017-12-19 15:52:16 262

原创 通配符匹配-LintCode

判断两个可能包含通配符“?”和“*”的字符串是否匹配。匹配规则如下:'?' 可以匹配任何单个字符。'*' 可以匹配任意字符串(包括空字符串)。两个串完全匹配才算匹配成功。函数接口如下:bool isMatch(const char *s, const char *p)样例 一些例子:isMatch("aa","a") → falseisMatch("aa","aa") → trueisMa

2017-12-19 11:18:26 340

原创 杆子分割-LintCode

给一个 n 英寸长的杆子和一个包含所有小于 n 的尺寸的价格. 确定通过切割杆并销售碎片可获得的最大值.例如,如果棒的长度为8,并且不同长度部件的值如下,则最大可获得值为 22(通过切割两段长度 2 和 6 )样例:长度 | 1 2 3 4 5 6 7 8 --------------------------------------------价格 |

2017-12-19 09:01:58 382

原创 简化路径-LintCode

给定一个文档(Unix-style)的完全路径,请进行路径简化。样例 “/home/”, => “/home” “/a/./b/../../c/”, => “/c”挑战 :你是否考虑了 路径 = “/../” 的情况? 在这种情况下,你需返回”/”此外,路径中也可能包含双斜杠’/’,如 “/home//foo/”。 在这种情况下,可忽略多余的斜杠,返回 “/home/foo”思路: 首先考

2017-12-18 19:54:04 445

原创 Tree Longest Path With Same Value -LintCode

假设有一棵有 N 个节点的无向树, 编号为 1 到 N, 每一个节点都有一个int类型的值,不同的节点可以有相同的值。给一个长度为N的数组A,A[j]表示第j + 1个节点的值。再给一个长度为 (N - 1) * 2 的数组 E,对于任意的 0 <= j <= N - 2 都有 E[2 * j], E[2 * j + 1]表示节点 E[2 * j] 与节点 E[2 * j + 1]有边相连。返回具有

2017-12-18 15:22:45 1382

原创 数组中最大的差值-LintCode

给 m 个数组, 每一个数组均为升序. 现在你可以从两个不同的数组中挑选两个整数(每一个数组选一个)并且计算差值. 我们将两个整数 a 和 b 之间的差定义为它们的绝对差 |a - b|. 你的任务是去找到最大的差值.注意事项: 每一个给出的数组长度至少为 1. 至少有两个不为空的数组 m 个数组中所有整数的个数和在 [2, 10000]范围内. m 个数组中所有的整数均将在[-10000,

2017-12-13 15:45:22 1848

原创 Rearrange a String With Integers-LintCode

Given a string containing uppercase alphabets and integer digits (from 0 to 9), write a function to return the alphabets in the order followed by the sum of digits.样例: Given str = AC2BEW3, return ABCE

2017-12-12 14:07:42 336

原创 Find Elements in Matrix-LintCode

Given a matrix, find a element that appear in all the rows in the matrix.You can assume that there is only one such element.样例: For example: Given a matrix:[ [2,5,3], [3,2,1], [1,3,5]]return 3

2017-12-11 18:29:15 254

原创 左旋转二进制位-LintCode

位旋转 -—— 旋转(或循环移位)是类似于移位的操作, 不同的是一端脱落的那一位会被放回到另一端 在左旋转中, 左端掉下来的那一位会放在右端 假设 n 用 8 位二进制来存. 对 n = 11100101 左旋转 3 位, 得到 n = 00101111 (左移3位, 原先的前3位放在末尾). 如果 n 用 16 位或 32 位二进制来存, 那么对 n (000…11100101)左旋转了之后

2017-12-11 14:55:44 378

原创 Coin Change II-LintCode

You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number

2017-12-11 14:03:15 316

原创 形式为a^i b^j c^k的子序列数量-LintCode

给一字符串, 对形式为 a^i b^j c^k 的子序列进行计数, 即它由 i 个字符 a, 接着是 j 个字符 b, 然后是 k 个字符 c组成, i >= 1, j >= 1, k >= 1. Note: 如果两个子序列在原字符串中的index集合是不同的,则认为两个子序列不同。样例: 给定 s = abbc, 返回 3 子序列为 abc, abc 和 abbc 给定 s = abcabc

2017-12-10 21:16:36 485

原创 Digit Divide Numbers-LintCode

A Digit Divide Numbers is a number that is divisible by every digit it contains.For example, 128 is a Digit Divide Numbers because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, Digit Divide Number

2017-12-10 19:24:16 254

原创 计算最大值-LintCode

给一个字符串类型的数字, 写一个方法去找到最大值, 你可以在任意两个数字间加 + 或 *样例: 给出 str = 01231, 返回 10 ((((0 + 1) + 2) * 3) + 1) = 10 我们得到了最大值 10 给出 str = 891, 返回 73 因为 8 * 9 * 1 = 72 和 8 * 9 + 1 = 73, 所以73是最大值思路: 遍历字符串的每一位,转化为数字nu

2017-12-08 09:33:40 302

原创 重复子串-LintCode

给出一个整数数组,写一个程序把这个整数数组分成S1跟S2两部分,使S1中的和跟S2中的和的绝对值最小。如果有一个一个整数数组 S 有 n 个数,如果Subset1有 m 个数,Subset2必须有 n-m 个数并且 abs(sum(Subset1) – sum(Subset2)) 应该最小样例:给出nums = [1, 6, 11, 5],返回1// Subset1 = [1, 5, 6],和是12

2017-12-06 14:26:45 238

原创 最小划分-LintCode

给出一个整数数组,写一个程序把这个整数数组分成S1跟S2两部分,使S1中的和跟S2中的和的绝对值最小。如果有一个一个整数数组 S 有 n 个数,如果Subset1有 m 个数,Subset2必须有 n-m 个数并且 abs(sum(Subset1) – sum(Subset2)) 应该最小样例:给出nums = [1, 6, 11, 5],返回1// Subset1 = [1, 5, 6],和是12

2017-12-05 18:54:32 975

原创 验证满二叉树-LintCode

如果一棵二叉树所有节点都有零个或两个子节点, 那么这棵树为满二叉树. 反过来说, 满二叉树中不存在只有一个子节点的节点. 更多关于满二叉树的信息可以在这里找到满二叉树 1 / \ 2 3 / \ 4 5不是一棵满二叉树 1 / \ 2 3 / 4 样例: 给出树 {1,2,3}, 返回 true 给

2017-12-05 14:28:03 1226

空空如也

空空如也

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

TA关注的人

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