![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
时光未老丶
这个作者很懒,什么都没留下…
展开
-
Leetcode #557 Reverse Words in a String III
DescriptionGiven a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.NoteIn the string, each word is separated原创 2017-04-20 15:56:36 · 211 阅读 · 0 评论 -
Leetcode #171 Excel Sheet Column Number
DescriptionRelated to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.Example A -> 1 B -> 2 C -> 3 …原创 2017-03-12 23:57:00 · 155 阅读 · 0 评论 -
Leetcode #122 Best Time to Buy and Sell Stock II
DescriptionSay 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,原创 2017-03-12 23:43:14 · 148 阅读 · 0 评论 -
Leetcode #504 Base 7
DescriptionGiven an integer, return its base 7 string representation.NoteThe input will be in range of [-1e7, 1e7].Example Example 1: Input: 100 Output: “202” Example 2: Input: -7 Ou原创 2017-03-07 19:04:28 · 221 阅读 · 0 评论 -
Leetcode #387 First Unique Character in a String
DescriptionGiven a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Example s = “leetcode” return 0. s = “loveleetcode”, return 2.原创 2017-03-09 23:49:57 · 178 阅读 · 0 评论 -
Leetcode #349 Intersection of Two Arrays
DescriptionGiven 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 result原创 2017-03-09 23:39:01 · 150 阅读 · 0 评论 -
Leetcode #404 Sum of Left Leaves
DescriptionFind the sum of all left leaves in a given binary tree.Example 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respe原创 2017-03-09 23:34:15 · 154 阅读 · 0 评论 -
Leetcode #383 Ransom Note
DescriptionGiven 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 maga原创 2017-03-09 23:14:17 · 223 阅读 · 0 评论 -
Leetcode #104 Maximum Depth of Binary Tree
DescriptionGiven 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.Explaindfs裸搜,刚转行用python写,写的有点臭,后原创 2017-02-27 15:36:50 · 127 阅读 · 0 评论 -
Leetcode #448 Find All Numbers Disappeared in an Array
DescriptionGiven 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 arra原创 2017-02-27 15:06:05 · 137 阅读 · 0 评论 -
Leetcode #541 Reverse String II
DescriptionGiven a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse a原创 2017-03-13 10:16:17 · 255 阅读 · 0 评论 -
Leetcode #100 Same Tree
DescriptionGiven 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.Explain递原创 2017-03-30 11:17:39 · 155 阅读 · 0 评论 -
Leetcode #268 Missing Number
DescriptionGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.NoteYour algorithm should run in linear runtime complexity. Could you impl原创 2017-03-30 16:11:26 · 160 阅读 · 0 评论 -
Leetcode #350 Intersection of Two Arrays II
DescriptionGiven two arrays, write a function to compute their intersection.NoteEach element in the result should appear as many times as it shows in both arrays.The result can be in any order.Examp原创 2017-03-30 15:03:22 · 170 阅读 · 0 评论 -
Leetcode #206 Reverse Linked List
DescriptionReverse a singly linked list.Code# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(o原创 2017-03-30 14:37:19 · 147 阅读 · 0 评论 -
Leetcode #13 Roman to Integer
DescriptionGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Example input: DCXXI output: 621Codeclass Solution(object): def romanToInt原创 2017-03-30 14:32:18 · 151 阅读 · 0 评论 -
Leetcode #217 Contains Duplicate
DescriptionGiven 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原创 2017-03-30 14:01:45 · 165 阅读 · 0 评论 -
Leetcode #401 Binary Watch
DescriptionA binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant原创 2017-03-30 13:58:05 · 138 阅读 · 0 评论 -
Leetcode #409 Longest Palindrome
DescriptionGiven a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is n原创 2017-03-30 13:30:55 · 125 阅读 · 0 评论 -
Leetcode #242 Valid Anagram
DescriptionGiven 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.NoteYou may ass原创 2017-03-30 11:26:48 · 142 阅读 · 0 评论 -
Leetcode #169 Majority Element
DescriptionGiven 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 elem原创 2017-03-30 11:21:54 · 154 阅读 · 0 评论 -
Leetcode #520 Detect Capital
DescriptionGiven 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 in原创 2017-02-27 11:25:03 · 123 阅读 · 0 评论 -
Leetcode #292 Nim Game
DescriptionYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone w原创 2017-02-27 11:15:13 · 126 阅读 · 0 评论 -
Leetcode #476 Number Complement
DescriptionGiven a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.NodeThe given integer is guaranteed to fit within the range原创 2017-02-26 21:51:31 · 146 阅读 · 0 评论 -
Leetcode #136 Single Number
DescriptionGiven an array of integers, every element appears twice except for one. Find that single one.NodeYour algorithm should have a linear runtime complexity. Could you implement it without using原创 2017-02-27 15:09:56 · 124 阅读 · 0 评论 -
Leetcode #492 Construct the Rectangle
DescriptionFor 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, whos原创 2017-03-01 10:27:22 · 232 阅读 · 0 评论 -
Leetcode #506 Relative Ranks
DescriptionGiven 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”.NodeN is原创 2017-03-01 11:24:59 · 196 阅读 · 0 评论 -
Leetcode #283 Move Zeroes
DescriptionGiven 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.NoteYou must do this in-place without making a copy of t原创 2017-03-01 11:47:39 · 119 阅读 · 0 评论 -
Leetcode #226 Invert Binary Tree
DescriptionInvert a binary tree.Example 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1Explain递归翻转即可Code# Definition for原创 2017-03-01 11:06:45 · 126 阅读 · 0 评论 -
Leetcode #530 Minimum Absolute Difference in BST
DescriptionGiven a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example Input: 1 \ 3 / 2 Out原创 2017-03-01 10:58:30 · 315 阅读 · 0 评论 -
Leetcode #258 Add Digits
DescriptionGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.ExampleGiven num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one di原创 2017-03-01 10:08:09 · 110 阅读 · 0 评论 -
Leetcode #389 Find the Difference
DescriptionGiven 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 wa原创 2017-03-01 09:59:33 · 138 阅读 · 0 评论 -
Leetcode #167 Two Sum II - Input array is sorted
DescriptionGiven 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原创 2017-03-01 12:17:55 · 268 阅读 · 0 评论 -
Leetcode #455 Assign Cookies
DescriptionAssume 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 siz原创 2017-03-01 14:28:32 · 120 阅读 · 0 评论 -
Leetcode #485 Max Consecutive Ones
DescriptionGiven a binary array, find the maximum number of consecutive 1s in this array.NoteThe input array will only contain 0 and 1.The length of input array is a positive integer and will not exc原创 2017-02-27 11:03:07 · 125 阅读 · 0 评论 -
Leetcode #463 Island Perimeter
DescriptionYou 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 c原创 2017-02-27 10:56:19 · 125 阅读 · 0 评论 -
Leetcode #453 Minimum Moves to Equal Array Elements
DescriptionGiven 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.Example Input: [1原创 2017-03-06 00:21:16 · 127 阅读 · 0 评论 -
Leetcode #344 Reverse String
DescriptionWrite a function that takes a string as input and returns the string reversed.ExampleGiven s = “hello”, return “olleh”.Codeclass Solution(object): def reverseString(self, s): """原创 2017-02-27 10:39:59 · 104 阅读 · 0 评论 -
Leetcode #412 Fizz Buzz
DescriptionWrite a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “B原创 2017-02-27 10:33:59 · 152 阅读 · 0 评论 -
Leetcode #496 Next Greater Element I
DescriptionYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places o原创 2017-02-27 10:24:35 · 241 阅读 · 0 评论