自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(188)
  • 资源 (5)
  • 收藏
  • 关注

原创 leetcode - Create Maximum Number

题目:         https://leetcode.com/problems/create-maximum-number/思路:从nuns1中选[0, min(nums1.size(),k] 个数字,剩下的从nuns2选,选出来后按照规则组合成一个数字,最大的为答案。注意边界条件。class Solution{public: vector maxNumber(v

2016-03-04 14:41:14 704 2

原创 leetcode - Remove Invalid Parentheses

题目:https://leetcode.com/problems/remove-invalid-parentheses/思路:广度优先遍历。在返回最终结果res前,注意去重!class Solution{public: //参数kuohao代表此次递归里cur中左括号数量减去右括号数量的值,可见kuohao是非负整数 void removeInvalidParent

2016-03-03 16:59:24 601

转载 leetcode - Count of Smaller Numbers After Self

题目:    https://leetcode.com/problems/count-of-smaller-numbers-after-self/思路:    使用线段树,参考这里。class Solution{ class Node//线段树节点 { public: int ll,rr,cnt; // 在范围[ll,rr]内的值有cnt个 Node

2016-03-03 15:06:11 605

原创 leetcode - Maximum Product of Word Lengths

题目:https://leetcode.com/problems/maximum-product-of-word-lengths/提示:使用位操作class Solution {public:    int maxProduct(vector& words)     {        if(words.size()            re

2016-02-15 23:47:48 486

转载 leetcode - Minimum Height Trees

题目:https://leetcode.com/problems/minimum-height-trees/参考这里class Node{public: int id; unordered_set next; Node(int a) :id(a){}};class Solution {public: vector findMinHeightTre

2016-02-15 22:49:44 420

转载 leetcode - Super Ugly Number

题目:https://leetcode.com/problems/super-ugly-number/参考这里。注意一定代码中heap一定要使用multiset!!!class Node{public: int index, prime, val; Node(int a, int b, int c) :index(a), prime(b), val(c){}

2016-02-15 21:02:39 394

原创 leetcode - Best Time to Buy and Sell Stock with Cooldown

题目:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/参考这里class Solution {public: int maxProfit(vector& prices) { if (prices.size() <= 1) return 0; if (

2016-02-15 17:38:30 390

原创 leetcode - Range Sum Query - Mutable

题目:https://leetcode.com/problems/range-sum-query-mutable/思路:使用数据结构线段树,在NumArray的构造函数中递归构造线段树。//线段树节点class Node{public: int Min, Max, sum;//Min, Max表示该节点的区间为[Min,Max] Node* left,

2016-02-15 00:38:49 324

原创 leetcode - Additive Number

题目:https://leetcode.com/problems/additive-number/class Solution {public: long long str2num(string str){ stringstream ss(str); long long n; ss >> n; return n; } string num2str(l

2016-02-13 23:12:11 402

原创 合并k个有序数组

题目:合并k个有序数组。分析:利用一个大小为k的小根堆(代码里用multiset表示),每次取堆顶的数字,直到大根堆为空。struct node{ vector>* ptr; int i; int j; node(vector>* p, int a, int b) :ptr(p), i(a), j(b) {}};struct compare{ bool

2015-09-21 14:46:12 2448

原创 leetcode - Move Zeroes

题目:Move ZeroesGiven 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

2015-09-19 15:44:15 437

原创 leetcode - Integer to English Words

题目:Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.For example,123 -> "One Hundred Twenty Three"12345 -> "Twelve Th

2015-09-05 01:17:08 513

原创 【原题】求两个不相交的连续子数组的最大和

题目:         有一个整数数组n,a和b是n里两个互不相交的子数组。返回sum(a)+sum(b)的最大值。分析:新建两个数组left和right,left[i]表示n[0:i]的连续子数组的最大和,right[i]表示n[i:length-1]的连续子数组的最大和。left[i]+right[i+1]的最大值就是答案。int SumOfTwoSubarray(const

2015-08-30 23:50:14 2808

原创 letcode - Dungeon Game

题目:Dungeon GameThe demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knigh

2015-07-27 23:30:25 651

原创 leetcode - Search a 2D Matrix II

题目:Search a 2D Matrix IIWrite an efficient algorithm that searches for a value in anm x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending

2015-07-25 13:52:56 892

原创 leetcode - Sliding Window Maximum

题目:Sliding Window MaximumGiven an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the win

2015-07-18 11:49:33 949

原创 leetcode - Lowest Common Ancestor of a Binary Tree

题目:Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of

2015-07-11 10:55:28 896

转载 leetcode - Convert Sorted List to Binary Search Tree

题目:Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked l

2015-07-09 23:51:30 460

原创 leetcode - Decode Ways

题目:Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits,

2015-07-06 12:15:09 550

原创 leetcode- Permutations II

题目: Permutations II Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1

2015-06-29 14:52:24 683

原创 leetcode - Jump Game II

题目:Jump Game II Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length

2015-06-29 00:00:08 565

原创 leetcode - Next Permutation

题目:Next Permutation Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rea

2015-06-22 17:59:18 457

原创 leetcode - Divide Two Integers

题目:Divide Two Integers Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. 分析:1、设法在不溢出的前提下,把除数和被除数转化成正数进行计算。

2015-06-22 16:11:32 499

原创 leetcode - Merge k Sorted Lists

题目:Merge k Sorted ListsMergek sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 分析:用multiset作为小根堆,multiset的begin是value最小的结点。注意:

2015-06-21 09:45:02 757

转载 leetcode - Container With Most Water

题目:Container With Most WaterGiven n non-negative integers a1, a2, ...,an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints

2015-06-20 20:37:06 418

原创 leetcode - Longest Palindromic Substring

题目:Longest Palindromic Substring Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest

2015-06-20 16:35:32 628

原创 leetcode - Valid Number

题目:Valid NumberValidate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueclass Solution {public: bool is

2015-06-10 11:07:47 673

原创 leetcode - Regular Expression Matching

题目:Regular Expression Matching '.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The

2015-06-09 21:28:09 521

转载 leetcode - Count Complete Tree Nodes

题目:Count Complete Tree Nodes Given a complete binary tree, count the number of nodes.In a complete binary tree every level, except possibly the last, is completely filled, and all

2015-06-06 17:35:37 479

原创 manacher算法的实现

manacher算法的解释见 这里。//求字符串s中最大回文的长度,要求字符串s不包含字符‘#’int manacher(const string &s){ if (s.size() <= 1) return s.size(); //往s每个字符之间以及s的首尾都插入‘#’ string str(s.size() * 2 + 1, '#'); for (int

2015-06-05 11:51:31 1131

原创 【回文】leetcode - Shortest Palindrome

题目:Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by perf

2015-06-05 11:01:33 771

原创 leetcode - Missing Ranges

题目:Missing RangesGiven a sorted integer array where the range of elements are [0, 99]inclusive, return its missing ranges.For example, given [0, 1, 3, 50, 75], return[“2”, “4->49”, “51->74”, “

2015-06-04 16:15:00 760

原创 leetcode - One Edit Distance

题目:One Edit DistanceGiven two strings S and T, determine if they are both oneedit distance apart.Hint:1. If | n – m | is greater than 1, we know immediately both are not one-editdistance a

2015-06-04 15:27:10 621

原创 【动态规划】leetcode - Maximal Square

题目:Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0

2015-06-03 15:20:09 1112

转载 【字符串】KMP算法的实现

来源:脑客爱刷题vector GetNextArr(const string &match){ vector NextArr; if (match.empty()) return NextArr; if (match.size() == 1) return vector(1, -1); NextArr = vector(match.size()); NextArr

2015-06-02 11:07:53 417

原创 leetcode - Contains Duplicate III

题目:Contains Duplicate III Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at mo

2015-06-02 09:36:49 1047

原创 【动态规划】邮局选址问题

题目:有一条公路经过V个村庄,每一个村庄都处在整数的坐标点上(这里假设公路为数轴)。规划在这条公路上建立P个邮局,每一个邮局都要建在某个村庄上,要求让不同村庄的人到邮局要走的总路程最小。分析:用动态规划的办法,先把输入的村庄排序,然后计算只有一个邮局的情况,然后再根据已有的信息,计算p(p>=2)个邮局时的选址分布,其中p从小到大计算。class addr_in

2015-05-31 21:17:09 6837

转载 leetcode - The Skyline Problem

题目:leetcodehttps://leetcode.com/problems/the-skyline-problem/转载:http://blog.csdn.net/bachelorchen/article/details/46005999bool compare(const pair &p1,const pair &p2){ if(p1.first!

2015-05-26 16:56:59 1045

原创 leetcode - Shortest Palindrome

题目:leetcode Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can fin

2015-05-24 19:07:36 1019

原创 【经典】计算字符串表示的公式的值

题目:输入一个字符串,该字符串表示一个公式,公式里可能有整数、加减乘除符号和左右括号,计算公式的结果。如输入"48*((70-65)-43)+8*1" ,返回整数-1816.注意:1、假设公式不会出错,既不用考虑左右括号不配对、出现非法字符等情况。2、计算过程或结果不用考虑溢出。3、输入的公式中只有整数,没有小数。整数可能有负数,负数需要用括号括起来,如 “(-3)+4" 。在

2015-05-24 12:03:11 3192 1

VC++程序: 将字符串转换成公式并计算结果

int Calculate(string formula) 函数功能:输入一个字符串公式string formula,允许四则混合运算,然后输入公式中对应变量的取值,最后返回int类型计算结果。 变量的格式:必须由1位字母加1位数字组成,如a1、b2等。 如输入字符串 “(a1+b2)/(-100)”,以及a1=100,b2=300,得到结果-4。遇到小数则向下取整。 公式的格式: 1、只包含变量、常数、四则符号、小括号四种符号,不支持大括号和中括号 2、允许正数前加正号,如+100 3、不允许空括号,如 “8*( )” 4、允许负数,但负数必须加括号,如 "5/(-1)"。当负数在公式开头时,可不加括号, 如 "-a1+90"和“+a1+90” 都是对的 5、允许纯常数公式,如 “5*(-9)” 6、允许用户输入多余的空格,但空格不能造成公式错误, 如公式 “(1 08+a2)/a 3” 是错的,(- 7)和(- n5)是错的,去掉空格就对了。

2014-10-23

求字符的所有排列

求字符的全排列,如输入三个字符a、b、c,则它们的组合有a,b,c,ab,ac,bc,abc。

2014-06-08

判断二叉搜索树的前序遍历

《剑指offer》面试题24的相关题目。输入一个整数数组,判断该数组是不是某二叉搜索树的前序遍历。假设输入的数组的任意两个数字互不相同。

2014-06-08

从上到下打印二叉树结点

用队列实现从上到下打印二叉树每个节点,同一层的节点按照从左到右的顺序打印。用C++实现。

2014-06-08

N皇后问题C++代码

N皇后问题C++代码

2014-06-07

空空如也

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

TA关注的人

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