LeetCode
wdkirchhoff
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode Base 7
class Solution(object): def convertToBase7(self, num): """ :type num: int :rtype: str """ res= "" flag = 0 if num == 0: return "0原创 2017-03-30 19:41:10 · 520 阅读 · 0 评论 -
LeetCode 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”. For n原创 2017-03-20 20:22:54 · 367 阅读 · 0 评论 -
LeetCode 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.The原创 2017-03-20 20:38:55 · 504 阅读 · 0 评论 -
LeetCode Ransom Note
class Solution(object): def canConstruct(self, ransomNote, magazine): """ :type ransomNote: str :type magazine: str :rtype: bool """ magazine_k_v = {原创 2017-03-27 23:34:18 · 519 阅读 · 0 评论 -
LeetCode First Unique Character in a String
#coding=utf-8import stringclass Solution(object): def firstUniqChar(self, s): """ :type s: str :rtype: int """ k_v = {} t = [s.find(i) for i in str原创 2017-03-27 23:56:25 · 470 阅读 · 0 评论 -
LeetCode Minimum Moves to Equal Array Elements
#coding=utf-8class Solution(object): def minMoves(self, nums): """ :type nums: list[int] :rtype: int """ #该问题与每次自减一个元素,等价 res = 0 m = min(nu原创 2017-03-28 12:24:04 · 455 阅读 · 0 评论 -
LeetCode Island Perimeter
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 s原创 2017-03-21 19:05:01 · 333 阅读 · 0 评论 -
LeetCode Nim Game
You 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 will be the原创 2017-03-21 19:06:29 · 299 阅读 · 0 评论 -
LeetCode 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: 3 Explanation: The first two digits or the last three digits are consecutive 1s.原创 2017-03-21 19:15:57 · 410 阅读 · 0 评论 -
LeetCode Find All Numbers Disappeared in an Array
Given 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 array.Could you原创 2017-03-22 11:13:17 · 402 阅读 · 0 评论 -
LeetCode Detect Captital
Given 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 this word原创 2017-03-23 19:10:32 · 409 阅读 · 0 评论 -
LeetCode Delete Node in a Linked List
# Definition for singly-linked list.class ListNode(object): def __init__(self, x): self.val = x self.next = Noneclass Solution(object): def deleteNode(self, node): """原创 2017-03-30 19:31:46 · 528 阅读 · 0 评论 -
LeetCode Keyboard Row
Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.Example 1: Input: [“Hello”, “Alaska”, “Dad”, “Peace”] O原创 2017-03-20 20:03:57 · 428 阅读 · 0 评论 -
LeetCode Find the Difference
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 added in原创 2017-03-23 20:15:19 · 450 阅读 · 0 评论 -
LeetCode Invert Binary Tree
# Definition for a binary tree node.class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution(object): def invert原创 2017-03-25 23:35:36 · 388 阅读 · 0 评论 -
LeetCode Sum of Two Integers
# coding=utf-8class Solution(object): def getSum(self, a, b): """ :type a: int :type b: int :rtype: int """ MAX_INT = 0x7FFFFFFF MIN_INT = 0原创 2017-03-25 23:36:39 · 536 阅读 · 0 评论 -
LeetCode Add Digits
class Solution(object): def addDigits(self, num): """ :type num: int :rtype: int """ while num % 10 != num: s = str(num) num = sum([i原创 2017-03-25 23:54:33 · 526 阅读 · 0 评论 -
LeetCode Construct the Rectangle
import mathclass Solution(object): def constructRectangle(self, area): """ :type area: int :rtype: list[int] """ #x^2=area x = math.sqrt(area)原创 2017-03-26 00:31:31 · 471 阅读 · 0 评论 -
LeetCode Move Zeroes
class Solution(object): def moveZeroes(self, nums): """ :type nums: list[int] :rtype: void Do not return anything, modify nums in-place instead. """ i,j= 0,原创 2017-03-26 00:50:15 · 474 阅读 · 0 评论 -
LeetCode Relative Ranks
class Solution(object): def findRelativeRanks(self, nums): """ :type nums: list[int] :rtype: list[str] """ origin_nums = nums[:] nums.sort()原创 2017-03-26 15:43:25 · 499 阅读 · 0 评论 -
LeetCode Assign Cookies
class Solution(object): def findContentChildren(self, g, s): """ :type g: list[int] :type s: list[int] :rtype: int """ res = 0 g.sort()原创 2017-03-27 14:20:24 · 531 阅读 · 0 评论 -
LeetCode Majority Element
Given 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 element always原创 2017-05-12 10:14:24 · 425 阅读 · 0 评论 -
LeetCode 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-12 10:30:30 · 470 阅读 · 0 评论 -
LeetCode Excel Sheet Column Title
Excel Sheet Column Title Total Accepted: 18284 Total Submissions: 103291 My Submissions Question Solution Given a positive integer, return its corresponding column title as appear in an Excel sheet.F原创 2015-03-21 22:17:38 · 1591 阅读 · 0 评论 -
LeetCode Pow(x,n)
class Solution {public:double pow(double x,int n){ if(n<0)return 1.0/power(x,-n); return power(x,n); } double power(double x, int n) { if(n == 0) return 1; double temp =原创 2014-12-03 20:59:19 · 765 阅读 · 0 评论 -
LeetCode Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2014-12-04 08:44:58 · 816 阅读 · 0 评论 -
LeetCode N-Queens
又是一个八皇后问题:Given an integer n, return all distinct solutions to the n-queens puzzle.Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both原创 2014-12-03 21:08:38 · 843 阅读 · 0 评论 -
LeetCode N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.这个比N-Queens简单点,但还是一样的class Solution {public: int totalNQ原创 2014-12-03 23:22:59 · 863 阅读 · 0 评论 -
LeetCode Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2014-12-04 08:43:48 · 751 阅读 · 0 评论 -
LeetCode Reverse Bits
Reverse Bits Total Accepted: 8148 Total Submissions: 29905 My Submissions Question Solution Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary a原创 2015-03-20 20:12:11 · 3688 阅读 · 0 评论 -
LeetCode Same Tree
Same Tree Total Accepted: 52651 Total Submissions: 125166 My Submissions Question Solution Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered e原创 2015-03-20 22:50:12 · 4146 阅读 · 0 评论 -
LeetCode Number of 1 Bits
Number of 1 Bits Total Accepted: 10567 Total Submissions: 28552 My Submissions Question Solution Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known原创 2015-03-20 19:59:10 · 1921 阅读 · 0 评论 -
LeetCode Reverse Integer
Reverse Integer Total Accepted: 61132 Total Submissions: 219035 My Submissions Question Solution Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to sh原创 2015-03-20 20:53:06 · 2002 阅读 · 0 评论 -
LeetCode Rotate Array
Rotate Array Total Accepted: 12759 Total Submissions: 73112 My Submissions Question Solution Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,原创 2015-03-20 21:52:03 · 2521 阅读 · 3 评论 -
LeetCode Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II Total Accepted: 41127 Total Submissions: 108434 My Submissions Question Solution Say you have an array for which the ith element is the price of a given stock on da原创 2015-03-21 21:24:11 · 4250 阅读 · 0 评论 -
LeetCode Single Number
LeetCode Single Number原创 2014-11-20 22:43:46 · 840 阅读 · 1 评论 -
LeetCode Excel Sheet Column Number
Excel Sheet Column Number Total Accepted: 19547 Total Submissions: 52851 My Submissions Question Solution Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet,原创 2015-03-21 22:28:44 · 1563 阅读 · 0 评论 -
LeetCode Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array Total Accepted: 52196 Total Submissions: 165553 My Submissions Question Solution Given a sorted array, remove the duplicates in place such that each element appear原创 2015-03-22 17:18:13 · 1456 阅读 · 0 评论 -
LeetCode Remove Duplicates from Sorted Array II
Remove Duplicates from Sorted Array II Total Accepted: 32492 Total Submissions: 105872My SubmissionsQuestion Solution Follow up for "Remove Duplicates":What if duplicates are a原创 2015-02-15 23:21:10 · 934 阅读 · 1 评论 -
LeetCode Find Minimum in Rotated Sorted Array
Find Minimum in Rotated Sorted Array Total Accepted: 38126 Total Submissions: 115306 My Submissions Question Solution Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,原创 2015-04-15 21:29:23 · 823 阅读 · 0 评论
分享