
LeetCode
文章平均质量分 72
when_bounce
这个作者很懒,什么都没留下…
展开
-
167. 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 numbe原创 2018-01-19 17:32:55 · 149 阅读 · 0 评论 -
206. Reverse Linked List
题目描述:Reverse a singly linked list.class ListNode { int val; ListNode next; ListNode(int x) { val = x; } }思路一:迭代class Solution { public ListNode reverseList(ListNode原创 2018-01-24 17:56:40 · 200 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
题目描述: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, b原创 2018-01-17 13:53:06 · 192 阅读 · 0 评论 -
520. Detect Capital
题目描述:Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters i原创 2018-01-08 15:53:09 · 151 阅读 · 0 评论 -
690. Employee Importance
题目描述:You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id.For example, employee 1 is the leader of原创 2018-01-08 14:49:00 · 203 阅读 · 0 评论 -
695. Max Area of Island
题目描述:Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are原创 2018-01-08 14:19:05 · 150 阅读 · 0 评论 -
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 path from the root node down to the farthest leaf node.class TreeNode { int va原创 2018-01-07 20:40:19 · 129 阅读 · 0 评论 -
485. Max Consecutive Ones
题目描述:Given a binary array, find the maximum number of consecutive 1s in this array.Note:The input array will only contain 0 and 1.The length of input array is a positive integer and will not原创 2018-01-07 19:42:10 · 162 阅读 · 0 评论 -
136. 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 usi原创 2018-01-06 20:14:28 · 185 阅读 · 0 评论 -
349. Intersection of Two Arrays
题目描述:Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The resu原创 2018-01-16 15:21:15 · 236 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements
题目描述:Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.思路一:n:数组长度x:所有数相等原创 2018-01-16 14:39:27 · 187 阅读 · 0 评论 -
383. Ransom Note
题目描述:Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazin原创 2018-01-17 15:45:41 · 146 阅读 · 0 评论 -
169. 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 eleme原创 2018-01-17 16:26:55 · 158 阅读 · 0 评论 -
387. First Unique Character in a String
题目描述:Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.同点击打开链接思路一:class Solution { public int firstUniqChar(String s) { if原创 2018-01-19 17:19:20 · 204 阅读 · 0 评论 -
455. Assign Cookies
题目描述:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of原创 2018-01-19 16:31:50 · 149 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
题目描述:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array原创 2018-01-10 15:18:30 · 164 阅读 · 0 评论 -
696. Count Binary Substrings
题目描述:Give a string s, count the number of non-empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively.原创 2018-01-10 14:43:44 · 172 阅读 · 0 评论 -
258. Add Digits
题目描述:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only原创 2018-01-10 14:25:10 · 200 阅读 · 0 评论 -
13. Roman to Integer
题目描述:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路:基本字符:I V X L C D M相应的阿拉伯数字表示为:1 5 10 50 100 500 1000相同的数字连写,所表示的数等于这些数字相加得到的数,例如:III =原创 2018-01-18 16:07:35 · 144 阅读 · 0 评论 -
100. 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.思路一:递归c原创 2018-01-18 15:42:04 · 151 阅读 · 0 评论 -
404. Sum of Left Leaves
题目描述:Find the sum of all left leaves in a given binary tree.class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } }思路一:DFS迭代,利用Stack对于一个给定的结点,原创 2018-01-18 15:13:12 · 162 阅读 · 0 评论 -
447. Number of Boomerangs
题目描述:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of原创 2018-01-25 15:55:56 · 187 阅读 · 0 评论 -
744. Find Smallest Letter Greater Than Target
题目描述:Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target.Lette原创 2018-01-25 15:29:56 · 167 阅读 · 0 评论 -
171. Excel Sheet Column Number
题目描述:Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28原创 2018-01-16 13:43:35 · 252 阅读 · 0 评论 -
599. Minimum Index Sum of Two Lists
题目描述:Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest wi原创 2018-01-23 16:14:49 · 175 阅读 · 0 评论 -
237. Delete Node in a Linked List
题目描述:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with原创 2018-01-21 13:40:04 · 157 阅读 · 0 评论 -
563. Binary Tree Tilt
题目描述:Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right s原创 2018-01-21 11:42:53 · 169 阅读 · 0 评论 -
682. Baseball Game
题目描述:You're now a baseball game point recorder.Given a list of strings, each string can be one of the 4 following types:Integer (one round's score): Directly represents the number of p原创 2017-12-28 14:41:41 · 156 阅读 · 0 评论 -
717. 1-bit and 2-bit Characters
题目描述:We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11).Now given a string represented by several b原创 2018-01-12 14:48:34 · 144 阅读 · 0 评论 -
606. Construct String from Binary Tree
题目描述:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". A原创 2018-01-12 14:09:45 · 193 阅读 · 0 评论 -
653. Two Sum IV - Input is a BST
题目描述:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.class TreeNode { int val; Tre原创 2018-01-12 13:19:48 · 184 阅读 · 0 评论 -
728. Self Dividing Numbers
题目:A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also,原创 2017-12-27 20:01:20 · 150 阅读 · 0 评论 -
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.For example, given nums = [0, 1, 0, 3, 12], after calling原创 2018-01-11 14:57:55 · 132 阅读 · 0 评论 -
389. Find the Difference
题目描述:Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that w原创 2018-01-11 14:30:05 · 133 阅读 · 0 评论 -
371. Sum of Two Integers
题目描述:同点击打开链接Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.思路一:class Solution { public int getSum(int a, int b) { while (b != 0)原创 2018-01-11 14:08:49 · 142 阅读 · 0 评论 -
242. Valid Anagram
题目描述:Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.思路一:O(n)c原创 2018-01-21 13:50:52 · 175 阅读 · 0 评论 -
530. Minimum Absolute Difference in BST
题目描述:Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.class TreeNode { int val; TreeNode left; TreeNode原创 2018-01-21 14:22:29 · 150 阅读 · 0 评论 -
217. Contains Duplicate
题目描述:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every ele原创 2018-01-23 15:35:50 · 174 阅读 · 0 评论 -
492. Construct the Rectangle
题目描述:For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose l原创 2018-01-15 15:19:29 · 155 阅读 · 0 评论 -
598. Range Addition II
题目描述:Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive intege原创 2018-01-15 15:09:28 · 166 阅读 · 0 评论