自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(59)
  • 收藏
  • 关注

原创 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 242

原创 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 171

原创 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 178

原创 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 156

原创 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 165

原创 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 175

原创 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 148

原创 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 137

原创 python数据结构效率问题

这段时间在用python做LeetCode的时候发现一个问题,就是我无法把握一些操作的时间复杂度,常常在写法上就犯难了,看到别人的一些“一行式”感到很奇特,由于是c出身,实现上通常偏“底层”,很少用现有的模块,结果发现在时间上大不如那些使用模块的,后来搞了本《数据结构与算法 python语言描述》,确实看到很多有用的内容,特别记录一下。list和tuple采用分离式的线性表,len操作复杂度O(1)

2017-03-30 12:05:55 857

原创 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 149

原创 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 176

原创 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 169

原创 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 292

原创 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 168

原创 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 158

原创 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 203

原创 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 162

原创 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 164

原创 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 232

原创 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 246

原创 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 134

原创 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 125

原创 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:19:58 128

原创 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:18:32 148

原创 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 277

原创 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 128

原创 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 199

原创 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 134

原创 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 325

原创 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 244

原创 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 120

原创 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 146

原创 Leetcode #371 Sum of Two Integers

DescriptionCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -.ExampleGiven a = 1 and b = 2, return 3.Explain开始写了个按位处理的代码,发现在处理负数的时候比较麻烦,参考了大牛的代码,简单解释下:MAX_IN

2017-02-28 11:42:46 200

原创 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 139

原创 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 133

原创 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 144

原创 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 134

原创 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 140

原创 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 134

原创 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 133

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除