自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(44)
  • 收藏
  • 关注

原创 50. Pow(x, n)

Implement pow(x, n).思路: 二分法:需要注意的是n还可能是负数,其次是最小负数的绝对值等于最大正数+1;public class Solution { public double myPow(double x, int n) { if(n==1||x==0||x==1) return x; if

2016-09-23 13:43:43 163

原创 49. Group Anagrams

Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]思路: 题目意思是将具

2016-09-23 13:12:02 135

原创 48. Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路: 先将数组以中间行为标准翻转,然后再以主对角线为标准交换对应元素。时间复杂度:O(N*N)空间复

2016-09-23 00:13:08 144

原创 46.47. 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]

2016-09-22 23:45:11 159

原创 45. Jump Game II

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.Your goal is

2016-09-22 11:00:57 170

原创 43. Multiply Strings

Given two numbers represented as strings, return multiplication of the numbers as a string.Note:The numbers can be arbitrarily large and are non-negative.Converting the input string to integer

2016-09-21 14:34:06 121

原创 42. Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]

2016-09-21 11:24:07 128

原创 41. First Missing Positive

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant spa

2016-09-21 10:26:23 115

原创 39. 40.Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen fromC unlimited numb

2016-09-20 21:59:51 151

原创 38. Count and Say

The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or11.11 is read off as "two 1s" or 21.21 is read off as "one

2016-09-20 10:32:00 142

原创 37. Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.思路: 对每一个未定的元素,

2016-09-19 21:39:41 169

原创 36. Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.思路: 即判断每行每列和9个正方形中有没

2016-09-19 13:10:36 109

原创 35. Search Insert Position

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.

2016-09-18 15:17:00 113

原创 34. Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(log n).If the target is not found in

2016-09-18 14:45:53 119

原创 33.81.Search in Rotated Sorted Array

Suppose a sorted array 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).You are given a target value to search. If found in the array return it

2016-09-18 13:58:39 130

原创 32. Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is"()", whi

2016-09-18 10:17:13 125

原创 31. 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

2016-09-15 10:26:42 166

原创 30. Substring with Concatenation of All Words

You are given a string, s, and a list of words,words, that are all of the same length. Find all starting indices of substring(s) ins that is a concatenation of each word in words exactly once and

2016-09-14 21:25:04 136

原创 29. Divide Two Integers

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路: 需要注意的是Math.abs(Integer.MIN_VALUE)=Integer.MAX_VALUE+1;因此当遇到被除数是Integer.MIN_V

2016-09-14 19:29:36 207

原创 28. Implement strStr()

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.最直接的方式: 从头开始逐渐匹配,若不一样,则后移一位继续比较.时间复杂度:O(M*N) M/N分别为两个字符串的长度pub

2016-09-14 10:29:32 120

原创 26. 27. Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this in place with

2016-09-14 09:26:34 137

原创 25. Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked listk at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

2016-09-13 21:55:57 107

原创 24. Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You m

2016-09-13 21:13:32 169

原创 22. Generate Parentheses

public List generateParenthesis(int n) { List list=new ArrayList(); if(n<=0) return list; if(n==1){ list.add("()"); return list; }

2016-09-13 16:20:08 158

原创 21.23. Merge Two Sorted Lists /

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路:选择两个list中第一个元素最小的为基础,然后将另外一个list的元素逐渐和第一个list中的元素相比,

2016-09-13 15:38:09 172

原创 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 all val

2016-09-13 10:52:57 121

原创 19. Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the li

2016-09-13 10:05:44 120

原创 linux文件操作命令

cat输出到标准屏幕:输出文件内容到屏幕: cat filename输出文件内容的同时加上行号,行号从1开始编号: cat -n filename输出文件的同时编行号,但是不给空白行编号: cat -b filename输出到指定文件:也可以将文件内容加上行号输出到另外一个文件: cat -n filename1 > filename2也可以将多个文件连接起来输

2016-09-13 00:09:21 231

原创 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:Digit string

2016-09-12 21:20:12 106

原创 15. 16. 18.3Sum 4sum

Given an array S of n integers, are there elementsa, 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 d

2016-09-12 19:43:28 134

原创 14. Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.最简单的解题思路:首先遍历一遍找到长度最短的字符串a,因为最长的前缀小于等于a;这样处理之后减少比较次数,然后将其它字符串依次与其比较前缀,并逐渐更新前缀的长度,如果更小则更新,最后返回字串即可.时间复杂

2016-09-12 18:03:51 133

原创 13. Roman to Integer

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.时间和空间复杂度都是O(N).从后往前计算. public int romanToInt(String s) { //:Ⅰ(1)Ⅴ(5

2016-09-12 17:26:46 133

原创 12. Integer to Roman

Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解题思路:将其从大到小进行比较,相同的将多个相同数字写在一起. public String intToRoman(int num) { int[]

2016-09-12 17:17:31 133

原创 11. Container With Most Water

Given n non-negative integers a1,a2, ..., an, where each represents a point at coordinate (i,ai). n vertical lines are drawn such that the two endpoints of linei is at (i, ai) and (i, 0). Find t

2016-09-12 10:47:37 134

原创 10. Regular Expression Matching 44. Wildcard Matching

Implement regular expression matching with support for'.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input

2016-09-11 10:37:09 221

原创 shell 数组处理

bash支持一维数组,不支持多维数组,且没有限定数组的大小。数组的下表还是从0开始,下标可以是整数或算术表达式。数组定义:用括号表示数组,数组元素用空格符号分隔。其一般形式为:array=(value1 value2 value3)下标范围没有限制。数组元素读取:value=${array[index]}#使用@或×可以获取数组中所有的元素:${array[×]} ${

2016-09-08 10:35:03 447

原创 shell脚本bc浮点数运算

shell脚本若要进行浮点运算,得经过bc这个管道命令;bc常用有3个属性:scale指定输出小数点后几位,默认为0;ibase指定输入数据是几进制,默认是十进制;obase指定输出数据是几进制,默认是十进制;i=1.2j=10 echo "scale=0;$i*$j" | bc12.0echo "scale=0;obase=2;$i*$j" | bc1100.

2016-09-08 09:54:53 3565

原创 135. Candy

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on

2016-09-07 21:47:48 313

原创 137. 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

2016-09-07 09:57:10 129

原创 136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.要求:线性时间,常量空间异或:2个相同数异或为0,0与任意数异或还是等于原来的数。public int singleNumber(int[] nums) { int result

2016-09-07 09:43:47 121

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除