- 博客(17)
- 资源 (3)
- 收藏
- 关注
原创 ?最大子列和问题(Java)/[3]53. Maximum Subarray(Java)
算法1:二重循环,复杂度O(n²)import java.util.Scanner;public class MaxSubSum1 { public static int maxSubSum(int[] array) { int thisSum, maxSum = 0; for (int i = 0; i < array.length; i ++) {
2017-07-30 18:53:54 319
原创 384.Shuffle an Array(Java)
Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums);// Shuffle the array [1,2,3] and return its resul
2017-07-30 18:33:43 266
原创 ×347. Top K Frequent Elements(Java)
Given a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ? k ? number of unique ele
2017-07-14 22:19:41 225
原创 [4]169. Majority Element/[4]121. Best Time to Buy and Sell Stock(Java)
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always
2017-07-14 17:15:08 266
原创 387. First Unique Character in a String(Java)
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-07-14 16:23:28 300
原创 [3]122. Best Time to Buy and Sell Stock II(Java)
Say you have an array for which the i-th 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 an
2017-07-14 16:05:30 374
原创 171. Excel Sheet Column Number/168. Excel Sheet Column Title(Java/C++)
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 in C
2017-07-14 15:11:16 204
原创 238. Product of Array Except Self(Java)
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
2017-07-13 15:18:24 306
原创 283. Move Zeroes(C++/Java)
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your funct
2017-07-11 18:32:28 236
原创 ?371. Sum of Two Integers(C++)
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example : Given a = 1 and b = 2, return 3.class Solution { public: int getSum(int a, int b) {
2017-07-11 18:14:42 293
原创 ?104. Maximum Depth of Binary Tree(C++)
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.代码1:Depth-first-search(DFS)递归int maxDepth(T
2017-07-07 00:22:20 280
原创 136. Single Number(C++)
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me
2017-07-06 21:19:26 312
原创 412. Fizz Buzz(C++)
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-07-06 20:16:26 430
原创 344. Reverse String(Java/C++)
Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.完整cpp程序:#include<iostream> #include<cstring> #include<algorithm> using namespac
2017-07-04 20:12:01 338
原创 60. Permutation Sequence(C++)
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3):“123” “132” “213” “231” “312”
2017-07-04 18:48:15 407
原创 31. Next Permutation(C++)
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-07-04 18:06:36 277
原创 27. Remove Element(C++/Java)
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order
2017-07-04 16:05:17 290
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人