自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 LeetCode—maximum-subarray(最大子数组的和)—java

题目描述: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 th...

2018-06-28 22:01:54 733

原创 LeetCode—n-queens-ii(返回解决方案的总数)—java

题目描述:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路解析:跟第一个题一样的解决方法,但是需要注意的是这个是计数,计数的话要用数组,因为数组就会更新里面的值。如果行数等于总行数,就可以在解决方案...

2018-06-28 19:19:04 251

原创 LeetCode—n-queens(n皇后问题)—java

题目描述:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each...

2018-06-28 18:05:28 984

原创 LeetCode—powx-n(x的n次)—java

题目描述:Implement pow(x, n).思路解析:pow(x,n)分解为pow(x,n/2)*pow(x,n/2) ,但是需要区分奇数偶数。还要看n的正负号。代码:public class Solution { public double pow(double x, int n) { if(n>=0) return power(x,n...

2018-06-24 14:22:25 238

原创 LeetCode—anagrams(返回由相同字母组成的单词)—java

题目描述:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路解析:首先判空然后需要创建HashMap来存储排序好的字符串,以及对应有相同字母组成的ArrayList。把每个字符串Arrays.sort以后,再以HashM...

2018-06-24 14:00:51 1053

原创 LeetCode—rotate-image(顺时针旋转90度)—java

题目描述: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?思路解析:旋转赋值交换就可以了代码:public class Solution { public void ro...

2018-06-21 21:33:51 710

原创 LeetCode—permutations-ii(有重复数字的排列)—java

题目描述:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].思路解析:这个题...

2018-06-21 20:44:49 507

原创 LeetCode—permutations_combinations_permutations-sequence(全排列——DFS深度优先搜索)—java

题目描述:Given a collection of 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], and[3,2,1].思路解析:https://blog.csdn.net/L...

2018-06-21 20:03:16 310

原创 LeetCode—jump-game-ii(跳跃数组的步长,返回最小步数)——java

题目描述: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 t...

2018-06-21 17:17:08 2480

原创 LeetCode—jump-game(跳跃步数为数组给的值)—java

题目描述: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 y...

2018-06-21 16:15:04 723

原创 LeetCode—wildcard-matching(正则表达式匹配)—java

题目描述:Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t...

2018-06-21 14:52:51 519

原创 LeetCode—multiply-strings(string表示的两个数字相乘)—java

题目描述: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.思路解析:大数乘法,首先大数是由字符串组成,并且高位在左,低位在右,为了乘起来方...

2018-06-21 11:25:05 2601

原创 LeetCode—trapping-rain-water(可以装多少水)—java

题目描述: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], ...

2018-06-21 08:54:53 758

原创 LeetCode—combination-sum-ii(不能重复选取元素,来组成目标值)—java

题目描述:Given a collection of candidate numbers ( C ) and a target number ( T ), find all unique combinations in C where the candidate numbers sums to T .Each number in C may only be used once in the com...

2018-06-14 21:55:47 450

原创 LeetCode—combination-sum(从给出的数组中组成目标数字)—java

题目描述:Given a set of candidate numbers ( C ) and a target number (T ), find all unique combinations in C where the candidate numbers sums to T .The same repeated number may be chosen from C unlimited n...

2018-06-14 21:13:44 291

原创 LeetCode—count-and-say(计数并说出来)—java

题目描述:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"o...

2018-06-14 17:30:47 499

原创 LeetCode—sudoku-solver(数独的解法)—java

题目描述: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.A sudoku puzzle......a...

2018-06-14 16:16:55 1318

原创 LeetCode—valid-sudoku(是不是满足数独条件)—java

题目描述: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'.'.A partially filled sudoku w...

2018-06-14 11:41:01 277

原创 LeetCode—search-insert-position(找到指定的值,否则是可能的位置)—java

题目描述: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...

2018-06-13 11:44:30 190

原创 LeetCode—search-for-a-range(找一个值的范围)—java

题目描述: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 t...

2018-06-13 11:01:47 646

原创 LeetCode—search-in-rotated-sorted-array(旋转数组)—java

LeetCode: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 7might become4 5 6 7 0 1 2).You are given a ...

2018-06-12 14:27:19 440

原创 LeetCode—longest-valid-parentheses(最长匹配的括号)—java

题目描述: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"()", which ha...

2018-06-11 17:07:56 316

原创 LeetCode—next-permutation(下一个排列)—java

题目描述: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 possibl...

2018-06-10 23:03:49 979

原创 LeetCode—substring-with-concatenation-of-all-words(找给出子串数组组成的所有子串的位置)—java

题目描述:You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and witho...

2018-06-10 17:49:54 306

原创 LeetCode—divide two integers(不用加减乘除做除法)—java

题目描述:Divide two integers without using multiplication, division and mod operator.思路解析:判空,返回0使用long类型的变量存储division和divisor的绝对值如果除数小于被除数,返回0使用加法完成除法,注意保存加了多少倍,使用嵌套循环,外层控制division大于divisor,里层控制倍数增加一倍是否比d...

2018-06-10 17:26:59 375

原创 LeetCode—divide-two-integers(分为两个整数)—java

题目描述:Divide two integers without using multiplication, division and mod operator.思路解析:判空,返回0使用long类型的变量存储division和divisor的绝对值如果除数小于被除数,返回0使用加法完成除法,注意保存加了多少倍,使用嵌套循环,外层控制division大于divisor,里层控制倍数增加一倍是否比d...

2018-06-08 15:55:29 968

原创 LeetCode—implement-strstr(找到字符串中的指定子串)—java

题目描述:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.思路解析:遍历给出的haystack字符串,如果剩下的长度小于needle的长度,返回null如果找到一致的单字符,就循环遍历,直到遍历的...

2018-06-08 10:44:01 197

原创 LeetCode—remove-element(从数组中删除给出的元素)—java

题目描述:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.思路解析...

2018-06-08 09:43:09 405

原创 LeetCode—remove-duplicates-from-sorted-array(有序数组中删除重复的元素)—java

题目描述:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place wit...

2018-06-08 09:22:39 175

原创 LeetCode—reverse-nodes-in-k-group(k个一组反转链表)—java

题目描述:Given a linked list, reverse the nodes of a linked list k 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 i...

2018-06-08 01:15:08 698

原创 LeetCode—swap-nodes-in-pairs(成对结点的交换)—java

题目描述:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only consta...

2018-06-07 23:36:54 518

原创 LeetCode—merge-k-sorted-lists(归并排序链表)—java

题目描述:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路解析:归并排序是排列数组的,现在应用到排列list这里来复习一下Merge Sort(对于数组操作),参考Wikipedia:归并操作(merge),也叫归并算法,指的是将两个已经排序的序列...

2018-06-07 21:25:23 486

原创 LeetCode—generate-parentheses(所有括号的组合)—java

题目描述: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:"((()))", "(()())", "(())()", "()(())", "()()()"...

2018-06-07 20:06:38 806

原创 LeetCode—valid-parentheses(括号校验)—java

题目描述: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 valid but"(]"and...

2018-06-07 17:00:09 228

原创 LeetCode—remove-nth-node-from-end-of-list(删除链表倒数第n个结点)—java

题目描述:Given a linked list, remove the n th 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 ...

2018-06-07 14:04:02 160

原创 LeetCode—letter-combinations-of-a-phone-number(手机数字键中字母组合)—java

题目描述: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 ...

2018-06-07 13:32:59 542

原创 LeetCode—4sum(四个数求和)—java

题目描述:Given an array S of n integers, are there elements a, b, c, and d in Ssuch that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a q...

2018-06-07 10:55:16 504

原创 LeetCode—3sum-closest(三个数的和最近的)—java

题目描述:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have ex...

2018-06-06 22:17:49 361

原创 LeetCode—3sum(求和)—java

题目描述:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) must ...

2018-06-06 18:27:41 584

原创 LeetCode—longest-common-prefix(最长公共前缀)—java

题目描述:Write a function to find the longest common prefix string amongst an array of strings.思路解析:将字符串数组的第一个进行比较,不可能有公共字符串比它还长了然后两层循环,第一层是第一个字符串的长度,0到strs.length()-1第二层是每个字符串的第i个位置,先确定有这个位置,然后判断是否一致。如果没...

2018-06-06 16:07:59 365

空空如也

空空如也

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

TA关注的人

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