![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
UESTC_kb216
这个作者很懒,什么都没留下…
展开
-
leetcode485: Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv原创 2017-02-09 08:55:15 · 149 阅读 · 0 评论 -
leetcode515: Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]广度优先搜索用队列,深度优先搜索用堆原创 2017-02-23 20:51:55 · 393 阅读 · 0 评论 -
leetcode504: Base 7
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e原创 2017-02-15 19:07:25 · 252 阅读 · 0 评论 -
leetcode551: Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A student could be原创 2017-04-18 20:18:06 · 431 阅读 · 0 评论 -
leetcode404: Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24原创 2017-04-18 20:44:13 · 187 阅读 · 0 评论 -
leetcode345: Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Note原创 2017-05-01 21:21:57 · 187 阅读 · 0 评论 -
leetcode167: 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 number原创 2017-04-06 19:24:04 · 162 阅读 · 0 评论 -
leetcode537: Complex Number Multiplication
Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1:Input: "1+1i", "1+1i"O原创 2017-04-06 19:25:33 · 276 阅读 · 0 评论 -
leetcode455: 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 a c原创 2017-04-06 19:50:53 · 148 阅读 · 0 评论 -
leetcode171: 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 一开始用了一个笨方法。。原创 2017-03-02 21:55:32 · 188 阅读 · 0 评论 -
leetcode500: Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.Example 1:Input: ["Hello", "Alaska", "Da原创 2017-02-14 20:32:35 · 303 阅读 · 0 评论 -
leetcode448: 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.原创 2017-02-22 21:30:14 · 140 阅读 · 0 评论 -
leetcode492: 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 length L原创 2017-02-10 10:12:46 · 141 阅读 · 0 评论 -
leetcode398: Random Pick Index
Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.Note:The array size c原创 2017-02-18 21:00:05 · 200 阅读 · 0 评论 -
leetcode506: Relative Ranks
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".Example 1:In原创 2017-02-10 22:11:40 · 857 阅读 · 0 评论 -
leetcode412: Fizz Buzz
要求:输出小于等于n的所用整数。3的倍数用Fizz替换,5的倍数用Buzz替换。3和5的公倍数用FizzBuzz替换,没什么难度注意:输出的是以String形式。String.valueOf(i)可以将int型i转化为String型public static List fizzBuzz(int n) { List result = new ArrayList(); for (int原创 2016-10-22 13:56:59 · 221 阅读 · 0 评论 -
leetcode482: License Key Formatting
Now you are given a string S, which represents a software license key which we would like to format. The string S is composed of alphanumerical characters and dashes. The dashes split the alphanumeric原创 2017-02-11 11:25:28 · 374 阅读 · 0 评论 -
leetcode463: Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely原创 2017-02-20 19:24:48 · 149 阅读 · 0 评论 -
leetcode481: Magical String
A magical string S consists of only '1' and '2' and obeys the following rules:The string S is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates原创 2017-02-12 11:59:29 · 234 阅读 · 0 评论 -
leetcode125: 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原创 2017-02-13 19:26:46 · 173 阅读 · 0 评论 -
leetcode151: Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place原创 2017-05-02 13:11:54 · 202 阅读 · 0 评论 -
leetocde557: Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contes原创 2017-04-20 21:15:56 · 164 阅读 · 0 评论 -
leetcode628: Maximum Product of Three Numbers
要求:Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24原创 2017-07-04 21:30:20 · 219 阅读 · 0 评论 -
leetcode26: 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 pla原创 2017-07-05 19:56:14 · 157 阅读 · 0 评论 -
leetcode617: Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tr原创 2017-06-15 18:42:04 · 496 阅读 · 0 评论 -
leetcode657: Judge Route Circle
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is represented原创 2017-08-20 20:03:46 · 168 阅读 · 0 评论 -
leetcode654: Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum tree constructed f原创 2017-08-21 14:29:10 · 268 阅读 · 0 评论 -
leetcode75: Sort Colors
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原创 2017-08-25 15:30:57 · 223 阅读 · 0 评论 -
leetcode745: 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.Letter原创 2018-01-03 19:23:47 · 264 阅读 · 0 评论 -
leetcode728: 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, a原创 2017-12-28 20:36:31 · 264 阅读 · 0 评论 -
leetcode561: Array Partition I
要求:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as原创 2017-07-03 20:12:34 · 211 阅读 · 0 评论 -
leetcode69: Sqrt(x)
要求:Implement int sqrt(int x).Compute and return the square root of x.注意:使用牛顿梯度法计算平方根,看百度百科或者维基百科 public int mySqrt(int x) { if (x== 0) return 0; double sol = 1; double res = 0原创 2017-07-02 20:56:12 · 146 阅读 · 0 评论 -
leetcode216: Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is a原创 2017-06-20 19:25:51 · 165 阅读 · 0 评论 -
leetcode344: Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".直接用StringBuffer中的reserve方法 public String reverseString(String s) {原创 2017-04-23 17:55:01 · 156 阅读 · 0 评论 -
leetcode 566: Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dim原创 2017-05-17 19:26:22 · 169 阅读 · 0 评论 -
leetcode 581: Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need to fin原创 2017-05-18 21:42:43 · 234 阅读 · 0 评论 -
leetcode73:Set Matrix Zeroes
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原创 2017-05-19 16:33:11 · 178 阅读 · 0 评论 -
leetcode611: Valid Triangle Number
Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Example 1原创 2017-06-15 20:28:13 · 776 阅读 · 0 评论 -
leetcode 593: Valid Square
要求:Given the coordinates of four points in 2D space, return whether the four points could construct a square.The coordinate (x,y) of a point is represented by an integer array with two integer原创 2017-05-21 19:44:28 · 1273 阅读 · 2 评论 -
leetcode624: Maximum Distance in Arrays
Given m arrays, and each array is sorted in ascending order. Now you can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance betw原创 2017-06-18 17:04:53 · 369 阅读 · 0 评论