- 博客(36)
- 资源 (3)
- 收藏
- 关注
原创 15. 3Sum && 16 sum closet && 18 4sum
public List> threeSum(int[] nums) { List> res = new ArrayList>(); if(nums.length<=2) return res; Arrays.sort(nums); for(int i=0;i<nums.length-1;i++
2017-09-24 21:02:42 293
原创 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2017-09-20 22:54:42 172
原创 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positi
2017-09-20 22:06:06 240
原创 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right at
2017-09-20 18:16:17 235
原创 62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the
2017-09-19 21:01:19 266
原创 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]. 题目略难(对我来说),于是又惨参考答案:思路是,首先因为输入的List不一定是有序的,那就先对其进行排
2017-09-19 20:30:43 313
原创 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defi
2017-09-18 22:20:51 368
原创 59. Spiral Matrix II && 54. Spiral Matrix
Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3, You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2017-09-18 21:59:53 348
原创 55. Jump Game
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.Determine if
2017-09-18 21:24:52 307
原创 344. Reverse String
Discuss Pick One Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh". 注意runtime error !!如果只是遍历会超时 下面注释掉的就是超时的方法
2017-09-17 00:12:36 147
原创 38. Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or11.11 is read of
2017-09-16 23:58:14 116
原创 66. Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits
2017-09-16 22:55:58 249
原创 100. Same Tree
Discuss Pick OneGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the s
2017-09-15 22:32:42 153
原创 168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 十进制转26进制的问题
2017-09-15 21:19:31 117
原创 171. Excel Sheet Column Number
Given 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 类似26进制,当A出现在个位时代表1
2017-09-15 20:55:07 193
原创 25. Reverse Nodes in k-Group 还未解决!!!
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of
2017-09-14 20:06:29 136
原创 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())"
2017-09-14 18:43:53 159
原创 162. 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
2017-09-13 18:46:01 209
原创 283. Move Zeroes
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 fu
2017-09-13 18:33:04 140
原创 182. Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com |+----+---------+For ex
2017-09-13 18:09:42 145
原创 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alw
2017-09-12 20:17:15 160
原创 78. Subsets
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets. For example,If nums = [1,2,3], a solution is: [ [3], [1], [
2017-09-12 19:21:08 142
原创 167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers
2017-09-12 10:05:09 209
原创 35. Search Insert Position&& 278. First Bad Version
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2017-09-10 12:55:03 129
原创 39. Combination Sum &&40. Combination Sum II
Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen f
2017-09-09 21:43:11 163
转载 java中length,length(),size()区别
1 java中的length属性是针对数组说的,比如说你声明了一个数组,想知道这个数组的长度则用到了length这个属性.2 java中的length()方法是针对字符串String说的,如果想看这个字符串的长度则用到length()这个方法.3.java中的size()方法是针对泛型集合说的,如果想看这个泛型有多少个元素,就调用此方法来查看!这个例子来演示这两个方法和一个属性的用法
2017-09-09 20:48:37 176
原创 13. Roman to Integer &&12. Integer to Roman
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.【罗马数字】1~9: {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};10~90: {
2017-09-09 11:54:02 159
原创 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints: Could negative integers be palindromes? (ie, -1)If you are thinking of converting t
2017-09-08 21:57:29 103
原创 101. 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
2017-09-08 17:13:32 147
原创 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input case
2017-09-08 14:48:57 163
原创 7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321 Have you thought about this?Here are some good questions to ask before coding. Bonus points for you if
2017-09-07 20:25:50 126
原创 53. 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
2017-09-06 23:01:40 162
原创 34. Search for a Range
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the ta
2017-09-06 20:13:50 288
转载 Java stack 类
stack参考点击打开链接vector 参考点击打开链接stack是一类很重要的数据结构,其重要特性就是“先进后出“。其在Java中对应的是stack类。栈是Vector的一个子类,它实现了一个标准的后进先出的栈。堆栈只定义了默认构造函数,用来创建一个空栈。 堆栈除了包括由Vector定义的所有方法,也定义了自己的一些方法。Java Vector 类Vect
2017-09-01 21:23:36 270
原创 20. Valid Parentheses
问题描述:Given a string containing just the characters '(', ')','{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are al
2017-09-01 21:15:53 104
原创 17. Letter Combinations of a Phone Number
问题描述:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Dig
2017-09-01 19:14:39 292
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人