自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 429. N-ary Tree Level Order Traversal

Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example, given a 3-ary tree:/*// Definition for a Node.class Node { ...

2019-02-08 08:13:56 108

原创 133. Clone Graph

Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph contains a label (int) and a list (List[UndirectedGraphNode]) of its neighbors. There is an edge between the ...

2019-02-07 05:35:39 89

原创 110. Balanced Binary Tree

Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of every node never differ ...

2019-02-06 05:03:13 102

原创 702. Search in a Sorted Array of Unknown Size

Given an integer array sorted in ascending order, write a function to search target in nums. If target exists, then return its index, otherwise return -1. However, the array size is unknown to you. Y...

2019-02-01 07:05:23 212

原创 121. Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), ...

2019-02-01 03:25:37 65

原创 300. Longest Increasing Subsequence

Given an unsorted array of integers, find the length of longest increasing subsequence.Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is [2,3,7,101], therefor...

2019-01-31 06:34:53 82

原创 64. Minimum Path Sum(DP)

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at an...

2019-01-31 06:17:30 76

原创 146. LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if the...

2019-01-30 05:08:02 148

原创 202. Happy Number

Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of...

2019-01-29 04:12:07 56

原创 170. Two Sum III - Data structure design

Design and implement a TwoSum class. It should support the following operations: add and find.add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which...

2019-01-27 05:24:56 62

原创 136. Single Number

Given a non-empty array of integers, every element appears twice except for one. Find that single one.Input: [2,2,1]Output: 1class Solution { public int singleNumber(int[] nums) { //hashs...

2019-01-27 04:42:43 53

转载 int和Integer的区别

-----int和Integer的区别1.从定义上来看int 是基本类型,直接存数值(类似的还有float、double、String、char)Integer是对象,用一个引用指向这个对象(类似的有Float、Double、String)2.从复杂度来看,Java 中的数据类型分为基本数据类型和复杂数据类型int 是前者;Integer 是后者(也就是一个类)3.初始化的方式不同i...

2019-01-27 04:41:51 123

原创 129. Rehashing(当hashtable不够时需要扩容)

/** * Definition for ListNode * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solu...

2019-01-25 03:57:57 217

原创 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.class Solution { public void moveZeroes(int[] nums) { if(n...

2019-01-23 02:42:44 50

原创 75. Sort Colors

Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the int...

2019-01-22 04:38:33 56

原创 15. 3Sum(综合题)---unique pair

Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.class Solution { public List<Li...

2019-01-20 06:39:15 136

原创 349. Intersection of Two Arrays

Given two arrays, write a function to compute their intersection.Example:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2]三种方法:1.sort&merge2.hashset3.binary search//binary searchclass ...

2019-01-19 04:04:12 57

原创 21. 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.Dummy node/** * Definition for singly-linked list. * pu...

2019-01-18 06:32:17 61

原创 Merge Two Sorted Arrays

Merge two given sorted integer array A and B into a new sorted integer array.思路:两个排好序的数组合并在一起,取两数组第一个比大小,小的出来组成result的第一个,然后循环再一个个比,直到A数组或者B数组有一个变成空的,然后把剩下的不空的加到result里。算法:定义result的长度为A和B长度之和,设置三个变...

2019-01-18 04:43:34 137

原创 Reverse Linkedlist

Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL思路:一个node指向前一个(需要用temp存储.next本来该指向的node),然后向后移动,pre=cur,cur=temp算法:/**...

2019-01-16 04:15:43 102

原创 46. Permutations

Given a collection of distinct integers, return all possible permutations.class Solution { public List<List<Integer>> permute(int[] nums) { List<List<Integer>> res...

2019-01-15 08:50:52 70

原创 39. Combination Sum

Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repeate...

2019-01-13 08:27:11 157

原创 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 must exist. Assume that there is only one duplicate number, fi...

2019-01-12 02:40:51 47

原创 559. Maximum Depth of N-ary Tree

Given a n-ary 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./*// Definition for a Node.class Node {...

2019-01-11 05:38:47 60

原创 207. Course Schedule(拓扑排序topological sort 高频题目)

There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair:...

2019-01-11 04:32:45 103

原创 101. Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center)./** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left...

2019-01-10 06:33:54 50

原创 261. Graph Valid Tree(BFS版本)

Given n nodes labeled from 0 to n-1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.class Solution { public boole...

2019-01-10 04:21:09 162

原创 102. Binary Tree Level Order Traversal(BFS模板背诵并记忆)

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).class Solution { public List<List<Integer>> levelOrder(TreeNode ro...

2019-01-10 03:27:36 132

转载 Simple application of queue in Java

import java.util.LinkedList;import java.util.Queue;import org.junit.Before;import org.junit.Test;/** * 队列测试:实现类使用LinkedList * * Queue也有很多其他的实现类,比如java.util.concurrent.LinkedBlockingQueue。 *...

2019-01-10 03:20:10 62

原创 285. Inorder Successor in BST

Given a binary search tree and a node in it, find the in-order successor of that node in the BST.The idea is to compare root’s value with p’s value if root is not null, and consider the following two...

2019-01-08 12:01:13 58

原创 173. Binary Search Tree Iterator(背诵并记忆)

题目:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Stack 在java B...

2019-01-08 04:15:39 84

原创 236. Lowest Common Ancestor of a Binary Tree

Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1Output: 3Explanation: The LCA of nodes 5 and 1 is 3./** * Definition for a binary tree node. * public class TreeNode { * int val; * ...

2019-01-06 13:19:41 59

原创 98. Validate Binary Search Tree

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { ...

2019-01-06 05:43:36 68

转载 java中this关键字的作用

一、this关键字主要有三个应用:(1)this调用本类中的属性,也就是类中的成员变量;(2)this调用本类中的其他方法;(3)this调用本类中的其他构造方法,调用时要放在构造方法的首行。Public Class Student {String name; //定义一个成员变量nameprivate void SetName(String name) { //定义一个参数(局部变量...

2019-01-06 04:06:01 94

原创 114. Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place./** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * Tree...

2019-01-05 05:39:32 52

原创 104. Maximum Depth of Binary Tree(1.private 2.void)

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./** * Definition for a binary tree node...

2019-01-05 04:00:29 67

原创 257. Binary Tree Paths

Given a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.解题思路:建立一个新的ArrayList,站在root,左右分别处理,然后左右两边分别定义一个path来存储左子树再加上根节点,最后判断是否为叶子节点。class Solution { public Li...

2019-01-04 08:24:33 96

原创 108. Convert Sorted Array to Binary Search Tree

题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of t...

2019-01-04 05:59:46 64

原创 81. Search in Rotated Sorted Array II

需要消除重复的元素,跳过while(nums[start]==nums[mid]){start++;}完整代码class Solution { public boolean search(int[] nums, int target) { //check errors if(nums==null||nums.length==0){ return ...

2019-01-02 11:31:39 62

原创 leetcode#74 Search a 2D Matrix

leetcode心得#74. Search a 2D Matrix用两次binary search用一次binary search

2019-01-02 08:00:01 105

空空如也

空空如也

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

TA关注的人

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