- 博客(143)
- 资源 (1)
- 收藏
- 关注
原创 Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to find the
2017-06-07 14:20:40
298
原创 Can Place Flowers
Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Given a
2017-06-05 22:22:17
320
原创 二分法(查找元素及其上界与下界)
利用二分法去查找某个元素效率高,将所要查找的元素称为key,有时利用二分法进行查找key的上界与下界,下界通常为key第一次出现的位置,上界通常为第一个大于key的位置。1 寻找元素的代码:int find(int array[], int len,int key) { int left = 0, right = len ; // attention while (left
2017-06-04 15:42:41
1302
1
原创 [Array]Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle [ [2], [3,4], [6,5,
2017-05-20 21:03:10
254
原创 Find Minimum in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exist
2017-05-06 22:27:28
167
原创 Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that case
2017-05-06 21:52:01
155
原创 Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead.For example, given the array
2017-05-06 20:19:13
177
原创 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain duplic
2017-05-04 21:11:58
149
原创 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly
2017-05-04 20:56:08
158
原创 vector中size问题
首先看一段代码: vector<int> a{1,2,3}; cout << a.size() << endl; vector<int> b{}; cout << b.size() << endl; cout << a.size() - 3 << endl; cout << b.size() - 3 << endl;程序运行结果: 可以发现 b.size
2017-05-04 15:22:32
3401
原创 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set mu
2017-05-04 15:06:15
160
原创 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,1,2], [1,2,1], [2,1,1]
2017-05-04 11:04:04
160
原创 Permutations
Given a collection of distinct numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]
2017-05-04 10:49:08
164
原创 Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible orde
2017-05-04 10:21:50
183
原创 Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Input: k = 3, n =
2017-05-04 09:00:07
188
原创 Combination Sum
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C
2017-05-04 08:49:23
158
原创 Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.No
2017-05-04 08:41:24
132
原创 Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using extra space?方法:寻找进入环的第一个节点。
2017-05-03 17:13:31
143
原创 Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fin
2017-05-03 17:03:36
158
原创 Game of Life
According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a board with m by n ce
2017-05-03 09:41:56
156
原创 Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You sh
2017-05-03 08:57:03
168
原创 First Unique Character in a String
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Examples:s = “leetcode” return 0.s = “loveleetcode”, return 2. Note: You may assume
2017-05-02 20:34:26
142
原创 Relative Ranks
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: “Gold Medal”, “Silver Medal” and “Bronze Medal”.Example 1: Input: [5
2017-05-02 20:21:20
201
原创 Construct the Rectangle
For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L
2017-05-02 20:18:46
156
原创 Base 7
Given an integer, return its base 7 string representation.Example 1: Input: 100 Output: “202” Example 2: Input: -7 Output: “-10” Note: The input will be in range of [-1e7, 1e7].class Solution {p
2017-05-02 14:06:32
187
原创 Reshape the Matrix
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dimensio
2017-05-02 14:00:13
453
原创 Array Partition I
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl
2017-05-02 12:09:07
237
原创 Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For n
2017-05-02 11:46:30
193
原创 Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input:1 \ 3 / 2Output: 1Explanation: The minimum
2017-05-02 11:29:12
163
原创 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:1 / \ 2 2 / \ / \ 3 4 4 3 But the
2017-05-02 10:14:10
147
原创 Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.方法: 前序遍历,注意代码简洁度。 自己写的/** * Definition fo
2017-05-02 09:23:06
156
原创 Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree [3,9,20,null,null,15,7],
2017-05-01 17:34:01
130
原创 Diameter of Binary Tree
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may no
2017-05-01 17:00:58
177
原创 Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by
2017-05-01 16:43:49
163
原创 Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and sum = 2
2017-05-01 16:13:06
154
原创 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree:1 / \ 2 3 \ 5 All root-to-leaf paths are:[“1->2->5”, “1->3”]方法: 注意to_string的用法。/** * Defi
2017-05-01 16:02:42
133
原创 Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example:3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.方法: 树的结构
2017-05-01 15:35:10
177
原创 Path Sum III
You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it must go
2017-05-01 15:09:53
163
Concurrent C++ local code
2020-03-23
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人