
leetcode
文章平均质量分 55
zzhRex
这个作者很懒,什么都没留下…
展开
-
leetCode#338.Counting Bits
DescriptionGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: Fo...原创 2018-04-03 17:17:20 · 178 阅读 · 0 评论 -
leetCode#111. Minimum Depth of Binary Tree
DescriptionGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Code# Definition for a binary tr原创 2017-12-26 22:07:48 · 131 阅读 · 0 评论 -
leetCode#198. House Robber
DescriptionYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adja原创 2017-12-15 10:52:48 · 156 阅读 · 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-12-14 15:18:08 · 124 阅读 · 0 评论 -
leetCode#141. Linked List Cycle
DescriptionGiven a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?Code# Definition for singly-linked list.# class ListNode(object):# def __i原创 2017-12-14 14:25:56 · 136 阅读 · 0 评论 -
leetCode#100. Same Tree
DescriptionGiven 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.E原创 2017-12-22 17:04:48 · 159 阅读 · 0 评论 -
leetCode#83. Remove Duplicates from Sorted List
DescriptionGiven a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.Code# Definition for原创 2017-12-22 10:50:46 · 177 阅读 · 0 评论 -
leetcode#287. Find the Duplicate Number
DescriptionGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate原创 2017-11-24 23:36:06 · 161 阅读 · 0 评论 -
leetcode#136. Single Number
DescriptionGiven 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 u原创 2017-12-12 21:36:20 · 132 阅读 · 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-12-20 23:04:16 · 154 阅读 · 0 评论 -
leetCode#226. Invert Binary Tree
DescriptionInvert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia: This problem was inspired by this original tweet by Max How原创 2017-12-19 21:52:32 · 164 阅读 · 0 评论 -
leetcode#234. Palindrome Linked List
DescriptionGiven a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?Code# Definition for singly-linked list.# class ListNode:# def __ini原创 2017-11-22 23:32:56 · 181 阅读 · 0 评论 -
leetcode#168. Excel Sheet Column Title
DescriptionGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB Codeclass Solution: def conver原创 2017-11-21 22:16:31 · 163 阅读 · 0 评论 -
leetCode#617. Merge Two Binary Trees
DescriptionGiven 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 bin原创 2017-12-18 22:34:20 · 160 阅读 · 0 评论 -
leetCode#15. 3Sum
DescriptionGiven 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 con原创 2018-01-03 15:43:39 · 192 阅读 · 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...原创 2018-02-25 09:59:11 · 191 阅读 · 0 评论 -
leetCode#647. Palindromic Substrings
DescriptionGiven a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even ...原创 2018-03-01 18:09:23 · 141 阅读 · 0 评论 -
leetCode#303. Range Sum Query - Immutable
DescriptionGiven an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5...原创 2018-03-01 14:38:02 · 161 阅读 · 0 评论 -
leetCode#746. Min Cost Climbing Stairs
DescriptionOn a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reac...原创 2018-03-01 12:07:06 · 170 阅读 · 0 评论 -
leetCode#121. Best Time to Buy and Sell Stock
DescriptionSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of ...原创 2018-02-28 17:46:42 · 153 阅读 · 0 评论 -
leetCode#18. 4Sum
DescriptionGiven an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The原创 2018-01-09 14:15:55 · 125 阅读 · 0 评论 -
leetCode#16. 3Sum Closest
DescriptionGiven 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原创 2018-01-08 17:34:02 · 151 阅读 · 0 评论 -
leetCode#5. Longest Palindromic Substring
DescriptionGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: “aba” is also a valid原创 2018-01-08 16:22:31 · 148 阅读 · 0 评论 -
leetCode#119. Pascal's Triangle II
DescriptionGiven an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?Codeclass Solu原创 2017-12-29 17:40:36 · 125 阅读 · 0 评论 -
leetCode#118. Pascal's Triangle
DescriptionGiven numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Codeclass Solution(object)原创 2017-12-29 10:43:55 · 142 阅读 · 0 评论 -
leetCode#107. Binary Tree Level Order Traversal II
DescriptionGiven a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,nu原创 2017-12-28 17:02:05 · 141 阅读 · 0 评论 -
leetCode#4. Median of Two Sorted Arrays
DescriptionThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [原创 2018-01-03 22:35:11 · 139 阅读 · 0 评论 -
leetcode#283. Move Zeroes
DesciprtionGiven 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原创 2017-11-21 21:40:27 · 202 阅读 · 0 评论 -
leetcode#461. Hamming Distance
DescriptionThe Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x, y <原创 2017-11-16 15:04:18 · 179 阅读 · 0 评论 -
leetcode#394. Decode String
DescriptionGiven an encoded string, return it’s decoded string.The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that原创 2017-11-20 22:24:54 · 157 阅读 · 0 评论 -
leetcode#496. 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.T原创 2017-07-08 11:30:03 · 175 阅读 · 0 评论 -
leetcode#551. 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 rewarded原创 2017-07-08 09:48:47 · 312 阅读 · 0 评论 -
leetcode#70. Climbing Stairs
题目You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive in原创 2017-07-06 23:36:32 · 173 阅读 · 0 评论 -
leetcode#557. 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 contest"Outp原创 2017-07-15 21:53:11 · 187 阅读 · 0 评论 -
leetcode#11.Container With Most Water
一开始的代码nt maxArea(int* height, int heightSize) { int max = 0; if(heightSize == 0 || heightSize == 1){ return 0; } for(int i = 0; i < heightSize; i++){ for(int j = i + 1; j原创 2016-09-12 15:30:50 · 557 阅读 · 0 评论 -
leetcode#541. Reverse String II
题目Given 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 all of the原创 2017-07-15 15:23:29 · 272 阅读 · 0 评论 -
leetcode#69. Sqrt(x)
题目Implement int sqrt(int x).Compute and return the square root of x. 这题比较狗,题目显示返回值是int型,所以我就猜想那种开方结果不是正数的数应该不在测试用例里吧,结果写好了提交一看,还是有这种数的。正确答案是针对开方结果不是正数的结果,返回向下取整的结果。代码class Solution(object): def my原创 2017-07-05 22:45:05 · 166 阅读 · 0 评论 -
leetcode#552. Student Attendance Record II
题目Given a positive integer n, return the number of all possible attendance records with length n, which will be regarded as rewardable. The answer may be very large, return it after mod 109 + 7.A stude原创 2017-07-13 14:09:29 · 1550 阅读 · 0 评论 -
leetcode#38. Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as “one 1” or 11. 11 is read off as “t原创 2017-07-02 23:11:14 · 239 阅读 · 0 评论 -
leetcode#628. 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: 24Note: The length of the give原创 2017-07-02 23:22:12 · 326 阅读 · 0 评论