leetcode
文章平均质量分 65
陈善亮-BUPT
专注机器学习与数据挖掘
展开
-
【leetcode】136. Single Number【java】使用异或
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 e原创 2017-01-18 09:52:15 · 616 阅读 · 0 评论 -
【leetcode】113. Path Sum II【java】
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2017-01-08 14:49:14 · 933 阅读 · 0 评论 -
【leetcode】112. Path Sum【java】
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原创 2017-01-06 17:08:15 · 599 阅读 · 0 评论 -
【leetcode】74. Search a 2D Matrix【java】
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 sorted from left to right.The first integer of each原创 2016-12-20 16:56:50 · 632 阅读 · 0 评论 -
【leetcode】73. Set Matrix Zeroes【java】
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m原创 2016-12-20 15:10:42 · 627 阅读 · 0 评论 -
【leetcode】72. Edit Distance【java】
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2016-12-20 09:50:44 · 668 阅读 · 0 评论 -
【leetcode】111. Minimum Depth of Binary Tree【java】
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 bin原创 2017-01-06 16:12:52 · 405 阅读 · 0 评论 -
【leetcode】93. Restore IP Addresses【java】
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2016-12-29 10:25:30 · 727 阅读 · 0 评论 -
【leetcode】110. Balanced Binary Tree【java】
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 diffe原创 2017-01-05 17:26:29 · 612 阅读 · 0 评论 -
【leetcode】109. Convert Sorted List to Binary Search Tree【java】 简单易懂的方法
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * public class ListNode { * int val;原创 2017-01-05 16:11:57 · 511 阅读 · 0 评论 -
【leetcode】108. Convert Sorted Array to Binary Search Tree【java】
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.递归/** * Definition for a binary tree node. * public class TreeNode { * int val; * T原创 2017-01-05 15:31:58 · 520 阅读 · 0 评论 -
【leetcode】107. Binary Tree Level Order Traversal II【java】
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,1原创 2017-01-05 10:47:15 · 450 阅读 · 0 评论 -
【leetcode】105. Construct Binary Tree from Preorder and Inorder Traversal【java】
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Definition for a binary tree node. * publ原创 2017-01-05 10:12:51 · 250 阅读 · 0 评论 -
【leetcode】104. Maximum Depth of Binary Tree【java】三种实现方法:递归、BFS、DFS
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 bin原创 2017-01-04 16:02:19 · 378 阅读 · 0 评论 -
【leetcode】103. Binary Tree Zigzag Level Order Traversal【java】使用队列,简单容易理解的方法
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2017-01-03 22:47:19 · 427 阅读 · 0 评论 -
【leetcode】114. Flatten Binary Tree to Linked List【java】
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2017-01-08 16:22:34 · 725 阅读 · 0 评论 -
【leetcode】75. Sort Colors【java】
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2016-12-21 09:06:53 · 282 阅读 · 0 评论 -
【leetcode】135. Candy【java】
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原创 2017-01-18 09:44:13 · 526 阅读 · 0 评论 -
【leetcode】134. Gas Station【java】
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2017-01-17 22:05:59 · 613 阅读 · 0 评论 -
【leetcode】125. Valid Palindrome【java】
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原创 2017-01-12 16:17:24 · 597 阅读 · 0 评论 -
【leetcode】131. Palindrome Partitioning【java】
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return[ ["aa","b"],原创 2017-01-16 16:28:53 · 634 阅读 · 0 评论 -
【leetcode】99. Recover Binary Search Tree【java】简单又容易理解的中序遍历的方法
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis原创 2017-01-01 20:21:55 · 421 阅读 · 0 评论 -
【leetcode】94. Binary Tree Inorder Traversal【java】
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursive solu原创 2016-12-29 15:34:34 · 281 阅读 · 0 评论 -
【leetcode】97. Interleaving String【java】动态规划,并有详细解释
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r原创 2017-01-01 11:33:16 · 1123 阅读 · 0 评论 -
【leetcode】123. Best Time to Buy and Sell Stock III【java】
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may原创 2017-01-11 11:33:48 · 640 阅读 · 0 评论 -
【leetcode】122. Best Time to Buy and Sell Stock II【java】
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2017-01-11 11:31:58 · 506 阅读 · 0 评论 -
【leetcode】121. Best Time to Buy and Sell Stock【java】
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),原创 2017-01-11 11:29:26 · 233 阅读 · 0 评论 -
【leetcode】119. Pascal's Triangle II【java】
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?public class原创 2017-01-09 21:13:52 · 574 阅读 · 0 评论 -
【leetcode】118. Pascal's Triangle【java】
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]]public class Solu原创 2017-01-09 17:33:38 · 538 阅读 · 0 评论 -
【leetcode】116. Populating Next Right Pointers in Each Node【java】
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2017-01-09 14:58:45 · 351 阅读 · 0 评论 -
【leetcode】115. Distinct Subsequences【java】
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non转载 2017-01-09 10:25:23 · 357 阅读 · 0 评论 -
【leetcode】100. Same Tree【java】
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.中文:给定两颗二叉树原创 2016-12-27 10:16:43 · 569 阅读 · 0 评论 -
【leetcode】90. Subsets II【java】
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a sol原创 2016-12-26 16:49:13 · 1005 阅读 · 0 评论 -
【leetcode】89. Gray Code【java】
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2016-12-26 16:05:36 · 484 阅读 · 0 评论 -
【leetcode】26. 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 in place with con原创 2016-11-29 19:38:15 · 319 阅读 · 0 评论 -
【leetcode】44. Wildcard Matching
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原创 2016-12-10 17:42:39 · 323 阅读 · 0 评论 -
【leetcode】50. Pow(x, n)
Implement pow(x, n).Subscribe to see which companies asked this question需考虑n=0和n=Integer.MIN_VALUE的情况, 此处求结果用了二分法。public class Solution { public double myPow(double x, int n) {原创 2016-12-10 19:59:00 · 386 阅读 · 0 评论 -
【leetcode】48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).(将二维数组顺时针翻转90度)Follow up:Could you do this in-place?Subscribe to see which companies原创 2016-12-10 23:06:34 · 191 阅读 · 0 评论 -
【leetcode】56. Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]./** * Definition for an interval. * public c原创 2016-12-13 16:21:47 · 181 阅读 · 0 评论 -
【leetcode】58. 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原创 2016-12-14 09:54:23 · 308 阅读 · 0 评论