python
文章平均质量分 53
zzhRex
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
牛客#第一个只出现一次的字符
Description在一个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置Code之所以记录这道题,倒不是因为这道题难,而是为了记录下这道题在python下的解法。 这道题的常规解法就是遍历字符串,然后存在数组中,统计次数。最后遍历数组,得出第一个只出现了一次的字符。 然而由于python中的dict会自动排序(py...原创 2018-03-06 16:44:38 · 276 阅读 · 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 · 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 · 150 阅读 · 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 · 177 阅读 · 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 · 138 阅读 · 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 · 153 阅读 · 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 · 179 阅读 · 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 · 207 阅读 · 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 · 175 阅读 · 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 · 143 阅读 · 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 · 174 阅读 · 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 · 183 阅读 · 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 · 205 阅读 · 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 · 211 阅读 · 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 · 158 阅读 · 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 · 158 阅读 · 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 · 215 阅读 · 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 · 161 阅读 · 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 · 184 阅读 · 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 · 190 阅读 · 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 · 172 阅读 · 0 评论 -
牛客#机器人的运动范围
Description地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?Code一开始没注...原创 2018-03-07 23:31:28 · 416 阅读 · 0 评论 -
leetCode#125. Valid Palindrome
DescriptionGiven 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原创 2018-02-06 23:24:27 · 186 阅读 · 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 · 141 阅读 · 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 · 164 阅读 · 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 · 162 阅读 · 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 · 142 阅读 · 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 · 163 阅读 · 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 · 178 阅读 · 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 · 220 阅读 · 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 · 204 阅读 · 0 评论 -
leetcode#112. Path Sum
DescriptionGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree an原创 2017-07-31 15:01:33 · 214 阅读 · 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 · 194 阅读 · 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 · 341 阅读 · 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 · 192 阅读 · 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 · 205 阅读 · 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 · 303 阅读 · 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 · 191 阅读 · 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 · 1591 阅读 · 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 · 259 阅读 · 0 评论
分享