- 博客(27)
- 收藏
- 关注
原创 字典树的增、删、查、找前缀个数
//// 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 421
原创 数组中最大累积和且大小不超过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 670
原创 一点资讯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 432
原创 删除重复节点
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 2990
原创 单位
#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 247
原创 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 294
原创 二叉树中两个节点的最近公共节点
一。后序遍历1.如果本节点为空或者为c1/c2,则返回本节点2.后序遍历3.如果两个子树传的值都不为空,则返回本节点(说明找到了两个目标节点)4.如果有一个节点为空,则另一个为空的可能是目标节点或者已经找到的公共祖先,此时则上传该值即可。//// main.cpp// 二叉树中两个节点的最近公共节点//// Created by zjl on 16/9/1
2016-09-17 17:39:27 684
原创 找到二叉树中的最大搜索二叉树
题目给定一颗二叉树,已知其中所有节点的值都不一样,找到含有节点最多的二叉搜索树,并返回头节点。注:一个二叉树的子树的叶节点必须是该二叉树的叶节点。解答:1. 后续遍历2. 每次记录下最小值,最大值,节总数。 如果root左右节点符合,则总数相加后,返回此根节点;否则返回左右节点中节点数最多的节点。输入:
2016-09-14 17:51:47 960
原创 在二叉树中找到累加和为指定值的最长路径长度
给定二叉树头结点和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 1066
原创 打印二叉树的边界节点-代码指南
标准一: 打印边界节点输入:{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 1168
原创 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 249
原创 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 238
原创 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 343
原创 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 368
原创 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 208
原创 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 250
原创 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 406
原创 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 353
原创 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 798
原创 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 196
原创 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 270
原创 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 283
原创 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 888
原创 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 853
原创 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 483
原创 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 470
原创 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 227
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人