- 博客(91)
- 收藏
- 关注
原创 SQLZOO-1
http://sqlzoo.net/wiki/SELECT_from_Nobel_Tutorial#14 The expression subject IN ('Chemistry','Physics') can be used as a value - it will be 0 or 1. ( 如果subject in ('Chemistry','Physics')),value=1,如果sub...
2018-06-24 09:36:52 523
Leetcode 226[easy]---Invert Binary Tree(迭代入门题,tree-queue,stack 入门题,反复看)
思路:题意明了,无需多说。参考别人用三种方法解题,递归,stack 和queue,每种方法都很重要,都是解决Tree问题的基本方法。 1. 递归:一个函数调用了他自己本身 # 17root.left = self.invertTree(root.right) 进入第一个递归,调用自身自定义函数 invertTree(), 2. stack:1.将...
2018-02-28 00:32:11 167
Leetcode 226[easy]---Invert Binary Tree(迭代入门题,tree-queue,stack 入门题,反复看)
思路:题意明了,无需多说。参考别人用三种方法解题,迭代,stack 和queue,每种方法都很重要,都是解决Tree问题的基本方法。 1. 迭代 ...
2018-02-27 23:17:54 152
原创 Leetcode 5 [medium]--Longest Palindromic Substring
思路: 此题运用自定义函数helper(),找到回文序列的最核心序列,然后往string的两边走,直到左右两边的字符不同为止。
2018-02-26 05:51:41 119
原创 Leetcode 2[medium]-- Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...
2018-02-26 04:14:00 140
原创 Leetcode 11[medium]--Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two ...
2018-02-25 15:07:34 126
原创 Leetcode 9[easy]---Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the intege...
2018-02-25 05:58:23 108
原创 leetcode 6[medium]-ZigZag Conversion
思路:将给定的string的字符用zigzag的形式重新排列,然后输出新的排列字符串。比如:给定string="kevinaustinandrewlee" len=20 numsrow=4, 如下图,对于第1排和最后一排,只需要一次找到间隔step=numsrow*2-2的字符即可,对于第2排和第3排,除了间隔 'step' 的字符,还有和该字符间隔 step-2i字符。分三步,第一排,中间排和...
2018-02-24 04:56:29 132
原创 Leetcode 3[medium]--- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...
2018-02-22 13:43:18 127
原创 Leetcode 456[medium]--132 Pattern
Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input ...
2018-02-19 01:33:29 126
原创 Leetcode 682[easy]--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 points you get in this...
2018-02-17 23:28:01 198
原创 Leetcode 496[easy]--Next Greater Element I
You 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 of nums2.Th...
2018-02-15 23:14:26 121
leetcode 538[easy]---Convert BST to Greater Tree
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.思路:1. 二叉...
2018-02-12 04:42:09 99
原创 Leetcode 16[medium]--3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly...
2018-02-06 08:15:10 98
原创 Leetcode 15 [medium]--3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain d
2018-02-04 23:22:36 120
原创 leetcode 567【medium】---Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.Exam
2018-01-02 19:20:24 148
原创 leetcode 438[easy]---Find All Anagrams in a String
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be lar
2018-01-01 10:44:52 143
原创 leetcode 458[easy]---Poor Pigs
There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minutes. What is the minimum
2017-12-31 19:56:12 164
原创 leeetcode 238[medium]---Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n)...
2017-12-26 12:50:50 133
原创 leetcode 434[easy]---Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain any non-printable characters.E
2017-12-25 18:36:17 137
原创 leetcode 412[easy]---Fizz Buzz
Write 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 “Buzz”. Fo
2017-12-25 11:50:22 124
原创 leetcode 485[easy]---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-12-24 17:52:05 122
原创 leetcode 551[easy]-- 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 rewar
2017-12-23 22:24:22 125
原创 leetcode 520[easy]---Detect Capital
难度:easyGiven 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 l
2017-12-23 18:05:52 99
原创 leetcode 735[medium]---Asteroid Collision
难度:mediumWe are given an array asteroids of integers representing asteroids in a row.For each asteroid, the absolute value represents its size, and the sign represents its direction (posit
2017-12-22 20:08:07 204
原创 leetcode 495[medium]----Teemo Attacking
难度:mediumIn LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards Ashe and
2017-12-22 15:36:53 149
原创 leetcode 605[easy]---Can Place Flowers
难度:easySuppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both
2017-12-22 14:11:30 213
原创 leetcode 347[medium]--Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number
2017-12-20 00:29:14 133
原创 leetcode 581[easy]---- Shortest Unsorted Continuous Subarray
难度:easyGiven 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.Yo
2017-12-19 12:12:51 137
原创 leetcode 34[medium]---Search for a Range
难度:mediumGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the...
2017-12-18 23:37:14 158
原创 leetcode 367[easy]----Valid Perfect Square
难度:easyGiven a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Inp
2017-12-18 16:38:19 111
原创 leetcode 153[medium]---Find Minimum in Rotated Sorted Array
难度:easySuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You m
2017-12-18 13:22:22 90
原创 leetcode 88[easy]---Merge Sorted Array
难度: easyGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) t
2017-12-18 00:35:15 124
原创 leetcode 414[easy]---Third Maximum Number
难度: easyGiven a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).思路:找出
2017-12-17 16:11:24 138
原创 leetcode 228[medium]---Summary Ranges--两个while循环,反复看。
难度:medium思路:题意很简单,不多讲。借鉴别人的code,膜拜这种用两个while循环,将变态与静态分开的数分开的写法。
2017-12-17 13:52:12 186
原创 leetcode 229[medium]--- Majority Element II
难度:mediumGiven an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.思路:找到给定的array里面,出现次数超过总长度 1/3 的eleme
2017-12-16 20:43:33 117
原创 leetcode 118[easy]---Pascal's Triangle
难度:easyGiven numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return思路:帕斯卡三角形。每层的每个元素就是上一行两个相邻元素相加(第一个和最后一个元素是1)。用两个for循环实现。
2017-12-16 15:35:10 119
原创 leetcode 33[medium]---Search in Rotated Sorted Array
难度:mediumSuppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to
2017-12-15 23:53:33 112
原创 leetcode 26[easy]--- Remove Duplicates from Sorted Array
难度:easyGiven 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 by modifyi...
2017-12-15 14:03:36 102
原创 leetcode80[medium]--Remove Duplicates from Sorted Array II
难度:mediumFollow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with
2017-12-15 00:28:55 203
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人