自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(13)
  • 收藏
  • 关注

原创 Leetcode 20: Valid Parentheses

//括号匹配是典型的出栈入栈问题class Solution { public: bool isValid(string s) { vector<char> stack; if(s.length() <= 1 ) return false; while(s.length() > 0) ...

2018-03-30 09:31:39 104

原创 Leetcode 67: Add Binary

//字符串的输入可能会是比较大的数组,需要用字符串逐位相加class Solution { public: string addBinary(string a, string b) { string result = ""; int max_length = a.length() > b.length() ? a.length() : b.length(); int min_l...

2018-03-28 16:43:47 108

原创 Leetcode 38: Count and Say

// 利用递归,需要注意最后一个数不能忘了加进去1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one 2, then one 1" or 1211.class Solution { public: string countAndSay(int n) { i...

2018-03-28 11:20:49 120

原创 Leetcode 5: Longest Palindromic Substring

//最长回文,可以将字符串从中间拆开,按左右两部分,一个向左移一个向右移进行对称匹配,每次移动都以移动到的点为哨兵位置,进行对称匹配class Solution { public: string longestPalindrome(string s) { int solder = s.length() / 2; string longest_str = ""; longest_s...

2018-03-26 16:50:02 96

原创 Leetcode 290: word sum

// 此题需要注意的是,哈希表在存储的时候插入顺序可能是随机的,如果此时要求两个表的key的相应位置一一对应不可行,需要以value为键值再建一个表 class Solution { public: bool wordPattern(string pattern, string str) { vector<string> str_vec; while (str.find('...

2018-03-25 21:29:10 93

原创 Leetcode 205: Isomorphic Strings

// 寻找对称的单词,一个简单的思路是遍历第一个字符串,将每一个字母出现的位置组合成一个int数值,如egg中g为12,并存为哈希表,最后比较两个哈希表中每个对应字母的int数值是否相同。class Solution { public: bool isIsomorphic(string s, string t) { if (s.length() != t.length()) re...

2018-03-25 11:17:18 119

原创 Leetcode 18 : 4sum

/* 思路:将四个数的和转换为两两求和,先将两两之和的结果存到哈希表中,每个和都对应一个vector,用来存储数组中对应的位置。对哈希中每个值,在该表中寻找target-value,如果可以找到则把对应的vector交叉映射组合成一个四数数组,对每一个数组检查是否存在重复位置,对哈希中每个值,在该表中寻找target-value,如果可以找到则把对应的vector交叉映射组合成一个四数数组,对每一...

2018-03-25 11:08:56 115

原创 Leetcode 29 :Divide two integers

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution { public: int divide(int dividend, int divisor) { if (divisor == 0 || ...

2018-03-22 15:00:25 110

原创 九度oj:求哈夫曼树(小顶堆数据结构)

#include #include using namespace std; priority_queue,greater > Q;//建立小顶堆 //默认的大顶堆priority_queue Q; int main() { int n; while(scanf("%d",&n)!=EOF) { while(Q.empty() == false) Q.pop();

2017-10-12 17:28:34 275

原创 九度oj:求哈夫曼树(vector)

/*题目描述: 哈夫曼树,第一行输入一个数n,表示叶结点的个数。需要用这些叶结点生成哈夫曼树,根据哈夫曼树的概念,这些结点有权值,即weight,题目需要输出所有结点的值与权值的乘积之和。 输入: 输入有多组数据。 每组第一行输入一个数n,接着输入n个叶节点(叶节点权值不超过100,2<=n<=1000)。 输出: 输出权值。 样例输入: 5 1 2 2 5 9 样例输出: 37*/ #inclu

2017-10-12 17:25:12 198

原创 输出最小整数对,以第一个数为主键

/*题目描述: 第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。 输入: 输入有多组数据。 每组输入n,然后输入n个整数对。 输出: 输出最小的整数对。 样例输入: 5 3 3 2 2 5 5 2 1 3 6*/ #include #include using names

2017-10-12 17:08:29 271

原创 九度oj:对矩阵任意子方阵进行多种翻转操作

/*题目描述: 首先输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。 操作类型有四种: 1 2 表示:90度,顺时针,翻转4个数 1 3 表示:90度,顺时针,翻转9个数 2 2 表示:90度,逆时针,翻转4个数 2 3 表示:90度,逆时针,翻转9个数 输入: 输入有多组数据。 每组输入一个5 * 5的数组,

2017-10-12 17:05:35 240

原创 给定一个子串,寻找没有重复字符的最长子串

/* Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", w

2017-10-12 08:57:16 963

空空如也

空空如也

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

TA关注的人

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