
leetcode
文章平均质量分 53
weixin_36908057
这个作者很懒,什么都没留下…
展开
-
Add to List 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5# Definition for singly-linked list.# clas原创 2017-11-19 21:49:24 · 292 阅读 · 0 评论 -
237. Delete Node in a Linked List python
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-04-04 22:53:15 · 245 阅读 · 0 评论 -
217. Contains Duplicate python
Given 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 element原创 2017-03-26 22:53:28 · 238 阅读 · 0 评论 -
leetcode 401. Binary Watch python
A 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 bit o原创 2017-03-26 22:37:11 · 262 阅读 · 0 评论 -
13. Roman to Integer python
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.def romanToInt(self, s): roman = {'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V'原创 2017-04-02 20:55:25 · 440 阅读 · 0 评论 -
leetcode 530 python
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example: Input: 1 \ 3 / 2Output:1Explanation:T原创 2017-03-03 22:27:45 · 380 阅读 · 0 评论 -
leetcode python 461
leetcode python 461 计算hammingDistance原创 2017-02-12 10:38:59 · 413 阅读 · 0 评论 -
leetcode 500 keyboard row
leetcode 500 keyboardrow原创 2017-02-12 17:09:40 · 291 阅读 · 0 评论 -
leetcode 412 python
leetcode 412 python原创 2017-02-22 19:57:45 · 386 阅读 · 0 评论 -
leetcode 344 python
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh". Subscribe to see which companies asked this questionclass Sol原创 2017-02-22 20:27:28 · 371 阅读 · 0 评论 -
521 Longest Uncommon Subsequence I
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defined as the longest subsequence of one of these stri原创 2017-04-16 22:03:48 · 282 阅读 · 0 评论 -
561. Array Partition I
Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possibl原创 2017-05-07 22:06:26 · 315 阅读 · 0 评论 -
599. Minimum Index Sum of Two Lists
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest with the原创 2017-05-29 10:54:02 · 315 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array
Suppose 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 may assume no duplicate exist原创 2017-11-19 21:04:09 · 235 阅读 · 0 评论 -
Best Time to Buy and Sell Stock with Transaction Fee
Your are given an array of integers prices, for which the i-th element is the price of a given stock on day i; and a non-negative integer fee representing a transaction fee. You may complete as many t原创 2017-11-13 22:59:14 · 243 阅读 · 0 评论 -
495. Teemo Attacking
In 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 the poisoning time原创 2017-11-13 21:22:26 · 216 阅读 · 0 评论 -
718. Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays. Example 1: Input: A: [1,2,3,2,1] B: [3,2,1,4,7] Output: 3 Explanation: The repeated subar原创 2017-11-02 21:18:45 · 189 阅读 · 0 评论 -
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 it原创 2017-11-09 22:16:26 · 178 阅读 · 0 评论 -
717. 1-bit and 2-bit Characters
We have two special characters. The first character can be represented by one bit 0. The second character can be represented by two bits (10 or 11). Now given a string represented by several bits. Re原创 2017-10-30 20:28:53 · 252 阅读 · 0 评论 -
575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute these原创 2017-05-31 21:09:41 · 290 阅读 · 0 评论 -
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” Out原创 2017-05-30 15:16:47 · 529 阅读 · 0 评论 -
566. Reshape the Matrix
In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data. You’re given a matrix represented by a two-dimen原创 2017-05-07 23:26:13 · 333 阅读 · 0 评论 -
leetcode 463 python
You 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 completely原创 2017-02-22 21:47:56 · 371 阅读 · 0 评论 -
leetcode 485 python
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 consecutive 1s.原创 2017-02-23 21:36:42 · 720 阅读 · 0 评论 -
leetcode 167. Two Sum II - Input array is sorted python
Given 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 numbers su原创 2017-03-05 20:55:02 · 248 阅读 · 0 评论 -
leetcode 453. Minimum Moves to Equal Array Elements python
Given 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 incrementingn - 1 elements by 1.Example: Input:[1,2,3]Outpu原创 2017-03-08 20:52:25 · 297 阅读 · 0 评论 -
leetcode 455. Assign Cookies python
Assume 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 size of a coo原创 2017-03-05 21:10:34 · 450 阅读 · 0 评论 -
leetcode 504. Base 7 python
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e7]. clas原创 2017-03-08 21:05:28 · 486 阅读 · 0 评论 -
leetcode 383. Ransom Note python
Given 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 magazines ; ot原创 2017-03-10 20:47:50 · 278 阅读 · 0 评论 -
leetcode 404. Sum of Left Leaves python
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.class Solu原创 2017-03-10 21:10:04 · 314 阅读 · 0 评论 -
leetcode 481. Magical String python
A magical string S consists of only '1' and '2' and obeys the following rules:The string S is magical because concatenating the number of contiguous occurrences of characters '1' and '2' generates t原创 2017-03-10 21:23:59 · 237 阅读 · 0 评论 -
leetcode 349. Intersection of Two Arrays python
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return[2]. class Solution(object): def intersection(self, nums1原创 2017-03-12 21:07:26 · 183 阅读 · 0 评论 -
leetcode 122. Best Time to Buy and Sell Stock II python
Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one原创 2017-03-12 21:31:27 · 227 阅读 · 0 评论 -
leetcode 506. Relative Ranks python
Given 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".Example 1:Inpu原创 2017-03-05 20:34:34 · 647 阅读 · 0 评论 -
leetcode 258 python
leetcode 258 python原创 2017-03-03 20:33:52 · 203 阅读 · 0 评论 -
leetcode 389 python
Given 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 was ad原创 2017-02-26 18:12:34 · 199 阅读 · 0 评论 -
leetcode 292 python
leetcode 292 python原创 2017-02-26 14:36:43 · 326 阅读 · 0 评论 -
leetcode 283. Move Zeroes python
Given 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 your fu原创 2017-03-05 19:53:13 · 228 阅读 · 0 评论 -
leetcode 226 python
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1# Definition for a binary tree node.# class TreeNode(object):#原创 2017-03-03 20:55:32 · 306 阅读 · 0 评论 -
leetcode 492 python
Construct the Rectangle原创 2017-03-03 21:32:27 · 256 阅读 · 0 评论