java
文章平均质量分 52
bell06
变成一个沉迷code无法自拔的程序猿
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode题记——Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam原创 2017-09-25 23:13:14 · 187 阅读 · 0 评论 -
leetcode题记——Maximum Depth of Binary Tree
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.For example:Given binary tree [3,9,20,null...原创 2018-02-08 15:22:04 · 188 阅读 · 0 评论 -
leetcode题记——Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,15,7], ...原创 2018-02-08 15:22:59 · 145 阅读 · 0 评论 -
leetcode题记——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 the t...原创 2018-02-08 15:23:50 · 162 阅读 · 0 评论 -
leetcode题记——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 by...原创 2018-02-08 15:25:27 · 231 阅读 · 0 评论 -
leetcode题记——Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary tree node....原创 2018-02-08 15:26:19 · 154 阅读 · 0 评论 -
leetcode题记——Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum = 22...原创 2018-02-08 15:28:30 · 159 阅读 · 0 评论 -
leetcode题记——Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution { public List<Li...原创 2018-02-08 15:30:21 · 162 阅读 · 0 评论 -
leetcode题记——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 (ie, buy one and sell one share of the stock), des...原创 2018-02-08 15:31:46 · 166 阅读 · 0 评论 -
leetcode题记——Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindro...原创 2018-02-08 15:32:38 · 267 阅读 · 0 评论 -
leetcode题记——Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra mem...原创 2018-02-08 15:33:21 · 168 阅读 · 0 评论 -
leetcode题记——Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * class ListNode { * int val; * ListNod...原创 2018-02-08 15:34:19 · 146 阅读 · 0 评论 -
leetcode题记——Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘ c...原创 2018-02-08 15:35:15 · 145 阅读 · 0 评论 -
leetcode题记——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 su...原创 2018-02-08 15:36:09 · 179 阅读 · 0 评论 -
leetcode题记——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...原创 2018-02-08 15:37:06 · 136 阅读 · 0 评论 -
leetcode题记——Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always...原创 2018-02-08 15:38:03 · 187 阅读 · 0 评论 -
leetcode题记——Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z...原创 2018-02-08 15:38:45 · 148 阅读 · 0 评论 -
leetcode题记——Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2018-03-02 23:03:52 · 184 阅读 · 0 评论 -
leetcode题记——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 3But the...原创 2018-02-08 15:21:19 · 186 阅读 · 0 评论 -
leetcode题记——Same Tree
Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:In...原创 2018-02-08 15:19:25 · 151 阅读 · 0 评论 -
leetcode题记——Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional ...原创 2018-02-08 15:18:09 · 127 阅读 · 0 评论 -
leetcode题记——Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321思路:对数x从个位数逐步往前,先取余后除以10,需要注意的是java中integer数的范围是2^31-1至-2^31之间,倒序后可能会出现值溢出的情况,需要用long数值(java中的范围为2原创 2017-09-25 23:04:39 · 178 阅读 · 0 评论 -
leetcode题记——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 va原创 2017-09-25 22:52:34 · 179 阅读 · 0 评论 -
leetcode题记——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原创 2018-03-07 13:26:15 · 291 阅读 · 0 评论 -
leetcode题记——House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2018-03-07 13:27:44 · 212 阅读 · 0 评论 -
leetcode题记——Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.class Solution { public boolean isPalindrome(int x) { int a = x, h = 1; if (a < 0) return false;//排除负数...原创 2018-02-08 14:59:55 · 145 阅读 · 0 评论 -
leetcode题记——Longest Common Prefix
write a function to find the longest common prefix string amongst an array of stringsclass Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0) return ""; ...原创 2018-02-08 15:01:47 · 203 阅读 · 0 评论 -
leetcode题记——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.Example:Input: 1->2->4, 1->3->4Output: 1->1...原创 2018-02-08 15:04:06 · 162 阅读 · 0 评论 -
leetcode题记——Remove Duplicates from Sorted Array
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 by modifying the ...原创 2018-02-08 15:05:24 · 123 阅读 · 0 评论 -
leetcode题记——Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-place ...原创 2018-02-08 15:06:20 · 164 阅读 · 0 评论 -
leetcode题记——Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Input:...原创 2018-02-08 15:08:16 · 142 阅读 · 0 评论 -
leetcode题记——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.Exam...原创 2018-02-08 15:10:18 · 154 阅读 · 0 评论 -
leetcode题记——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 the ...原创 2018-02-08 15:11:14 · 149 阅读 · 0 评论 -
leetcode题记——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 defined a...原创 2018-02-08 15:13:02 · 162 阅读 · 0 评论 -
leetcode题记——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 are s...原创 2018-02-08 15:14:19 · 135 阅读 · 0 评论 -
leetcode题记——Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution { public String addBinary(String a, String b) { if(a.length()<b....原创 2018-02-08 15:15:05 · 178 阅读 · 0 评论 -
leetcode题记——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 positive int...原创 2018-02-08 15:16:15 · 145 阅读 · 0 评论 -
leetcode题记——Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * D...原创 2018-02-08 15:17:32 · 243 阅读 · 0 评论 -
leetcode题记——Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 00000000原创 2018-03-02 23:08:56 · 197 阅读 · 0 评论
分享