- 博客(11)
- 资源 (6)
- 收藏
- 关注
原创 LeetCode题解:Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] has the
2016-03-04 09:22:17 640
原创 LeetCode题解:Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.Follow up: What if the BST is mod
2016-03-04 09:16:50 700
原创 LeetCode题解:Linked List Cycle
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ pub
2016-03-04 09:02:01 437
原创 LeetCode题解:Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case lette
2016-03-01 17:05:58 479
原创 LeetCode题解:Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].题意:先序遍历思路:代码:/** * Definition for a
2016-03-01 16:49:40 405
原创 LeetCode题解:Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in line
2016-03-01 16:48:25 519
原创 LeetCode题解:Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or turning off i
2016-03-01 16:37:47 609
原创 LeetCode题解:Best Time to Buy and Sell Stock with Cooldown
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 as many transactions as you like (ie, buy one and
2016-03-01 15:51:54 431
原创 LeetCode题解:Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For e
2016-03-01 15:47:31 684
原创 LeetCode题解:Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1,
2016-03-01 15:32:49 452
原创 LeetCode题解:Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ex
2016-03-01 15:22:33 420
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人