自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

原创 130. Surrounded Regions 将包围的符号变换 BFS & DFS & UNION find

Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,

2016-10-12 19:42:00 342 1

原创 字典树的增、删、查、找前缀个数

//// main.cpp// Trie 字典树的实现//// Created by zjl on 16/9/24.// Copyright © 2016年 zjl. All rights reserved.//#include #include #include using namespace std;const int number = 26;struct

2016-09-24 15:17:54 288

原创 数组中最大累积和且大小不超过K

对数中进行求解最大累积和且不超过K。这里的解决方法是以下网址https://www.quora.com/Given-an-array-of-integers-A-and-an-integer-k-find-a-subarray-that-contains-the-largest-sum-subject-to-a-constraint-that-the-sum-is-less-than-k

2016-09-01 15:45:08 273

原创 面试金典-2.5 链表加法(包含链表的创建)

两个链表代表两个整数,每个节点包含一个数位,这些数是正向存放的,编写函数求两个整数的和,并用链表形式返回结果。如: 两个整数为935165, 418则链表形式为 9 -> 3 -> 5 -> 1 -> 6 -> 5, 4 -> 1 -> 8由于root节点是高位,因此从链表尾开始求和,用到递归同时由于长短不一,因此需要对短的链表先进行补充节点,前面添加0节点//

2016-08-25 11:34:47 513

原创 输出一个集合的所有子集

输出字符串的所有子集如:对“abc”输出: c b bc a ac ab abc代码如下://// main.cpp// 输出一个集合的所有子集//// Created by zjl on 16/8/10.// Copyright © 2016年 zjl. All rights reserved.//#include #include usi

2016-08-10 19:36:39 3920

原创 建立二叉树

建立二叉树如对{1,2,2,3,3,null, null, 4,4}输入{1,2,2,3,3,0,0,4,4}TreeNode* create(vectorvec,int num){ TreeNode* root = new TreeNode(vec[0]); queue q; q.push(root); int i = 1; while(i <

2016-05-24 21:17:29 427

原创 int 与 string 相互转换

int转化为string1、使用itoa(int to string) 1 //char *itoa( int value, char *string,int radix); 2 // 原型说明: 3 // value:欲转换的数据。 4 // string:目标字符串的地址。 5 // radix:转换后的进制数,可以是10进制、16进制等。 6 // 返回

2016-05-05 16:14:38 1058

原创 string中split实现

对string中split的方法的实现其中pattern是需要划分的标识,是string类型vector split(string str, string pattern){ vector result; string::size_type pos; str+=pattern; int size = str.size();

2016-04-23 14:14:35 680

原创 char 转 string、vector 与 string互转

char 转 stringchar c;string str;stringstream stream;stream str = stream.str();string 转 vectorvector  vcBuf;string        stBuf("Hello DaMao!!!");--------------------------

2016-04-22 21:32:36 9643 2

原创 140. Word Break II 分词 DP

Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "

2016-10-12 09:33:57 320

原创 212. Word Search II 在二维字母表里找到给定word集合中的word子串

Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor

2016-10-11 22:36:19 339

原创 321. Create Maximum Number 找到两个数组中能合并的k个的最大数

Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k  from digits of the two. The relative order of the digits from the same array mus

2016-10-11 15:02:16 881

原创 一点资讯2

//// main.cpp// yidian1//// Created by zjl on 16/9/29.// Copyright © 2016年 zjl. All rights reserved.//#include #include using namespace std;int solve(vectornum, int n){ if(n <= 3)

2016-09-29 16:20:14 325

原创 删除重复节点

ListNode *deleteDuplicates(ListNode *head){ if(head == NULL) //如果头结点为空,则返回 return NULL; ListNode* pPreNode = NULL; ListNode* pNode = head; while(pNode != NULL){ ListNo

2016-09-26 20:04:39 769

原创 单位

#include #include #include using namespace std;int main(){    int n, a, b;    cin >> n >> a >> b;    vector hp(n+1);    for (int i = 1; i         cin >> hp[i];        i

2016-09-22 21:02:23 166

原创 wangyi3-数据挖掘研究员

//// main.cpp// wangyi3//// Created by zjl on 16/9/18.// Copyright © 2016年 zjl. All rights reserved.//#include #include #include using namespace std;int main(int argc, const char *

2016-09-18 22:32:04 197

原创 二叉树中两个节点的最近公共节点

一。后序遍历1.如果本节点为空或者为c1/c2,则返回本节点2.后序遍历3.如果两个子树传的值都不为空,则返回本节点(说明找到了两个目标节点)4.如果有一个节点为空,则另一个为空的可能是目标节点或者已经找到的公共祖先,此时则上传该值即可。//// main.cpp// 二叉树中两个节点的最近公共节点//// Created by zjl on 16/9/1

2016-09-17 17:39:27 512

原创 找到二叉树中的最大搜索二叉树

题目给定一颗二叉树,已知其中所有节点的值都不一样,找到含有节点最多的二叉搜索树,并返回头节点。注:一个二叉树的子树的叶节点必须是该二叉树的叶节点。解答:1. 后续遍历2. 每次记录下最小值,最大值,节总数。 如果root左右节点符合,则总数相加后,返回此根节点;否则返回左右节点中节点数最多的节点。输入:

2016-09-14 17:51:47 708

原创 在二叉树中找到累加和为指定值的最长路径长度

给定二叉树头结点和sum,打印等于sum的最长路径长度输入:{-3,3,-9,1,0,2,1,0,0,1,6,0,0}6输出:4//// main.cpp// 在二叉树中找到累加和为指定值的最长路径长度//// Created by zjl on 16/9/14.// Copyright © 2016年 zjl. All r

2016-09-14 12:19:38 856

原创 打印二叉树的边界节点-代码指南

标准一: 打印边界节点输入:{1,2,3,0,4,5,6,7,8,9,10,0,0,0,0,0,11,12,0,0,0,13,14,15,16}输出:1 2 4 7 11 13 14 15 16 12 10 6 3//// main.cpp// 打印二叉树的边界节点//// Created by zjl on 16/9/14.// Copyri

2016-09-14 11:16:40 832

原创 30. Substring with Concatenation of All Words 找出包含所有字典中词的开头

You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and

2016-09-07 11:36:19 177

原创 124. Binary Tree Maximum Path Sum 二叉树上的最大路径和

Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The

2016-09-05 11:07:33 173

原创 23. Merge k Sorted Lists 合并k个链表

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.1.我的思路      超时了开辟一个n个的指针空间,用来存放每一个链表的当前运行到的节点,然后依次连入到root上//// main.cpp// 23

2016-09-04 22:43:42 270

原创 41. First Missing Positive 第一个不在的正整数

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant

2016-09-04 17:57:48 259

原创 45. 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 at that position.Your goal i

2016-09-04 17:09:59 145

原创 Expression Add Operators

Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or *between the digits so they evaluate to the target value.

2016-09-04 14:56:11 176

原创 56. Merge Intervals 对区间进行合并

Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].1.我的解法 很简单 就一个个放到res里面,然后遍历每个元素,将每个元素与res里面的合并

2016-09-03 22:50:40 324

原创 123. Best Time to Buy and Sell Stock III

Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may

2016-09-03 21:07:18 257

原创 327. Count of Range Sum 满足某个范围数内的区间个数

Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j),

2016-09-03 17:55:26 643

原创 51. N-Queens

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.

2016-09-02 21:29:38 138

原创 87. Scramble String

Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr

2016-09-02 20:55:07 213

原创 99. Recover Binary Search Tree 将二叉查找树中乱序的两个元素值调整

Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis

2016-09-01 22:29:33 224

原创 164. Maximum Gap

Given 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 thek numbers in the window. Each time the sliding window

2016-09-01 20:06:35 770

原创 239. Sliding Window Maximum 固定的滑动窗口里找最大值

Given 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 thek numbers in the window. Each time the sliding window

2016-09-01 17:47:03 648

原创 115. Distinct Subsequences 字符串有多少种不同的删除方法能得到字符串t

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non

2016-09-01 16:34:36 247

原创 363. Max Sum of Rectangle No Larger Than K 最大累加子矩阵的和且不超过K

Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.Example:Given matrix = [ [1, 0, 1], [0, -2, 3]]k

2016-09-01 15:45:42 353

原创 330. Patching Array 给数组添上元素,使得满足存在所有1~n元素

Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Re

2016-09-01 11:19:03 164

原创 301. Remove Invalid Parentheses 去掉不合理的括号

Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.Note: The input string may contain letters other than the parentheses ( and ).

2016-08-31 16:10:12 904

原创 72. Edit Distance 最小编辑距离

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2016-08-31 15:12:47 248

原创 2017 网易有道内推

第三题:一个队列,先pop一个头结点放在队尾,再pop一个头结点输出其值并丢弃。最后输出的序列为1,2,3,。。。n问原始队列元素排列是什么输入:n     //n个数输出:一个串//// main.cpp// youdao3//// Created by zjl on 16/8/27.// Copyright © 2016年 zjl. All

2016-08-27 10:53:59 443

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