自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

原创 A

valid parenthesis  bst min path  rotate image  和2nd linkedlist reverse

2017-07-27 10:46:58 129 0

原创 Binary Tree的相关练习 104,111

104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest pat...

2017-06-03 21:58:12 232 0

原创 54. Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix:...

2017-05-29 11:22:11 137 0

原创 50. Pow(x, n)

实现power的功能 就是Pow(x,n) = x^n 但实际上按照今天学习的分治法里面的内容,其实x^n = x^(n/2)* x^(n/2) * x 在这道题目里,x的N次方可以看做:x^n = x^(n/2)*x^(n/2)*x^(n%2) 还需要考虑n为负数的情况 利用递归求解 ...

2017-05-27 22:39:08 98 0

原创 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? 意思...

2017-05-25 20:54:00 79 0

原创 Multiply String

题意就是给你两个字符串型的数字,给这两个数字做乘法。  如果直接转换成Integer做乘法就会溢出。  所以要一步一步来。 先给出代码: public class Solution { public String multiply(String num1, St...

2017-05-20 16:46:49 183 0

原创 46 permutations && 47 Permutation II

Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], ...

2017-05-20 10:31:04 127 0

原创 36. Valid Sudoku

The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially filled sudoku which i...

2017-05-17 14:33:31 84 0

原创 31. Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not po...

2017-05-15 22:29:49 113 0

原创 33. Search in Rotated Sorted Array 二分法

Suppose an array sorted in ascending order 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)....

2017-05-15 21:44:39 126 0

原创 24. Swap Nodes in Pairs using recursion

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-&...

2017-05-14 19:48:46 130 0

原创 22. Generate Parentheses----dfs

深度优先算法dfs==回溯法backtracking Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, giv...

2017-05-13 22:42:03 75 0

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

2017-05-13 16:58:27 87 0

原创 77. Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2...

2017-05-11 16:58:54 84 0

原创 40. Combination Sum II

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 ...

2017-05-11 10:48:15 79 0

原创 39. Combination Sum-dfs

Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sum...

2017-05-10 22:28:11 83 0

原创 17. Letter Combinations of a Phone Number 回溯算法

这道题是我第一次接触回溯算法,没写出来,感觉很难,小白真的是忧伤。。。 看了别人的答案,有些理解这个算法了,可是感觉自己还是独立写不出来,然后盲敲了一遍这个答案 Given a digit string, return all possible letter combinations ...

2017-05-10 20:22:32 195 0

原创 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. 题目是要求找到第一个出现指定字符串...

2017-05-09 16:57:56 103 0

原创 3SUM &&16. 3SUM closest && 18.4SUM

3 sum closest就是3sum 的变形, 输出和target最相近的值 基本思路和3sum相同,但是添加了一个closedistance变量 public class Solution { public int threeSumClosest(int[] nums, int t...

2017-05-09 15:56:04 86 0

原创 15 three sum 用到Arrays.sort 和 Arrays.asList()的方法

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 ...

2017-05-07 22:23:10 241 0

原创 12. Integer to Roman StringBuilder的运用以及StringBuffer和StringBuilder的比较

public class Solution { public String intToRoman(int num) { int[] values = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; String[] s...

2017-05-05 21:15:25 83 0

原创 13. Roman to Integer

罗马数字转换成整数: 首先要来了解一下罗马数字表示法,基本字符有7个:I,V,X,L,C,D,M,分别表示1,5,10,50,100,500,1000。 在构成数字的时候,有下列规则: 1、相同的数字连写,所表示的数等于这些数字相加得到的数,如:Ⅲ = 3; 2、小的数字在...

2017-05-05 20:05:37 120 0

原创 3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is &quo...

2017-05-02 10:49:04 142 0

原创 441. Arranging Coins

ou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total num...

2017-05-01 20:15:29 70 0

原创 2. Add Two Numbers

题目: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes...

2017-04-29 22:17:12 74 0

原创 496. Next Greater Element I

public class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { int len1 = nums1.length; int len2 = nums2.len...

2017-04-29 10:35:32 77 0

原创 225. Implement Stack using Queues

Implement the following operations of a stack using queues. push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.to...

2017-04-28 11:18:17 66 0

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

2017-04-25 22:06:44 89 0

原创 240. Search a 2D Matrix II && 74. Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are ...

2017-04-25 20:39:30 117 0

原创 436. Find Right Interval 要重新做!!

题目: Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the e...

2017-04-15 18:55:07 111 0

原创 454. 4Sum II

题目: Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero....

2017-04-15 18:45:21 62 0

原创 287. Find the Duplicate Number

题目: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number mu...

2017-04-15 18:43:43 59 0

原创 349. Intersection of Two Arrays & 350. Intersection of Two Arrays II

349的题目要求: Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2...

2017-04-12 09:49:56 86 0

原创 278. First Bad Version

题目: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails...

2017-04-10 23:55:14 81 0

原创 69. Sqrt(x)----binary search

mplement int sqrt(int x). Compute and return the square root of x. 题目就是要实现平方根的功能,但是要注意!!!当输入的数字不是完全平方数的时候需要返回距离它最下的完全平方数的平方根 比如当为7的时候,返回2 改了好几遍...

2017-04-10 20:37:47 269 0

原创 374. Guess Number Higher or Lower---------binary search

题目是: We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Ever...

2017-04-10 19:58:54 92 0

原创 167. Two Sum II - Input array is sorted-----binary search

题目如下: 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. ...

2017-04-10 15:40:03 160 0

原创 367. Valid Perfect Square

题目: Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in libr...

2017-04-09 22:42:07 107 0

原创 61. Rotate List 再做一次

Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2,...

2017-04-09 17:50:09 93 0

原创 160. Intersection of Two Linked Lists 要再做一遍

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = ...

2017-04-07 19:15:05 79 0

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