发布了文章2018-09-25
思路 递归/深度优先搜索, 维持一个全局变量记录深度 复杂度 时间复杂度O(n) 代码 {代码...} 思路 分治法 复杂度 时间复杂度O(n) 代码 {代码...} 思路 广度优先搜索的方法, 用queue来记录树的节点 复杂度 时间复杂度O(n) 空间复杂度O(log n) 代码 {代码...}
发布了文章2018-09-20
思路 递归/深度优先搜索, 维持一个全局变量记录深度 复杂度 时间复杂度O(n) 代码 {代码...} 思路 分治法 复杂度 时间复杂度O(n) 代码 {代码...} 思路 广度优先搜索的方法, 用queue来记录树的节点 复杂度 时间复杂度O(n) 空间复杂度O(log n) 代码 {代码...}
发布了文章2018-09-14
Given a binary tree, return the level order traversal of its nodes'values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null,null,15,7],return its level order traversal as: [ [3], [9,20], [15,7] ]
发布了文章2018-09-10
Given a collection of distinct integers, return all possiblepermutations.Example: Input: [1,2,3] Output: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ]
发布了文章2018-09-10
Given a set of distinct integers, nums, return all possible subsets(the power set).Note: The solution set must not contain duplicate subsets. Example: Input: nums = [1,2,3] Output: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
发布了文章2018-09-07
A linked list is given such that each node contains an additionalrandom pointer which could point to any node in the list or null.Return a deep copy of the list.
发布了文章2018-09-07
any single node in the list, and may not be necessarily the smallestvalue in the cyclic list.If there are multiple suitable places for insertion, you may chooseany place to insert the new value. After the insertion, the cycliclist should remain so...
发布了文章2018-09-06
Given a singly linked list, determine if it is a palindrome.Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true
发布了文章2018-09-06
Given a singly linked list, group all odd nodes together followed bythe even nodes. Please note here we are talking about the node numberand not the value in the nodes.You should try to do it in place. The program should run in O(1) spacecomplexit...
发布了文章2018-09-05
Write a program to find the node at which the intersection of twosingly linked lists begins. For example, the following two linked lists: A: a1 → a2 {代码...} Notes: If the two linked lists have no intersection at all, return null. Thelinked lists...
发布了文章2018-08-29
Given an array of n positive integers and a positive integer s, findthe minimal length of a contiguous subarray of which the sum ≥ s. Ifthere isn't one, return 0 instead.Example: Input: s = 7, nums = [2,3,1,2,4,3] Output: 2 Explanation: the subarr...
发布了文章2018-08-29
Given a binary array, find the maximum number of consecutive 1s inthis array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first twodigits or the last three digits are consecutive 1s. {代码...} The input array will only contain 0 and...
发布了文章2018-08-29
Given an array nums and a value val, remove all instances of thatvalue in-place and return the new length.Do not allocate extra space for another array, you must do this bymodifying the input array in-place with O(1) extra memory. The order of ele...
发布了文章2018-08-28
{代码...} 思路 因为要在两个数中取最小的值, 所以应该尽量找相邻的两个数一组, 这样才不会浪费一个大的数值。所以将数组排序, 找到两个中间大的那一个 复杂度 时间O(nlogn) 排序的复杂度空间O(1) 代码 {代码...}
发布了文章2018-08-28
{代码...} 思路 因为要在两个数中取最小的值, 所以应该尽量找相邻的两个数一组, 这样才不会浪费一个大的数值。所以将数组排序, 找到两个中间大的那一个 复杂度 时间O(nlogn) 排序的复杂度空间O(1) 代码 {代码...}
发布了文章2018-08-28
Write a function that takes a string as input and returns the stringreversed.Example 1: Input: "hello" Output: "olleh" Example 2: Input: "A man, a plan, a canal: Panama" Output: "amanaP :lanac a ,nalpa ,nam A"
发布了文章2018-08-27
把三角分为三种情况, 第一个1是每一行都有的, 结尾的1是从第二行才开始有, 然后中间的数字是从第三行开始, 对于i位置的数字是他前一行的i位置和i-1位置数字的和
发布了文章2018-08-25
Given a matrix of m x n elements (m rows, n columns), return allelements of the matrix in spiral order.Example 1: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output:[1,2,3,6,9,8,7,4,5] Example 2: Input: [ [1, 2, 3, 4], [5, 6, 7, 8], [9,10,11,...
赞了文章2018-08-24
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: {代码...} You should return [1,2,3,6,9,8,7,4,5].
发布了文章2018-08-24
Given a matrix of M x N elements (M rows, N columns), return allelements of the matrix in diagonal order as shown in the below image.Example: Input: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Output: [1,2,4,7,5,3,6,8,9] Explanation: Note: The total...