
Leecode
QU66Q
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Remove Element——Array
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.Th...原创 2016-08-10 16:15:22 · 123 阅读 · 0 评论 -
Roman to Integer——Math
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution(object): def romanToInt(self, s): """ :type s: str...原创 2016-08-13 21:00:15 · 134 阅读 · 0 评论 -
Excel Sheet Column Number——Math
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...原创 2016-08-13 21:01:55 · 155 阅读 · 0 评论 -
Majority Element——Array
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 al...原创 2016-08-13 21:02:08 · 126 阅读 · 0 评论 -
Reverse Linked List——Linked List
Reverse a singly linked list.# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(obj...原创 2016-08-13 21:03:06 · 139 阅读 · 0 评论 -
Power of Two
Given an integer, write a function to determine if it is a power of two.class Solution(object): def isPowerOfTwo(self, n): """ :type n: int :rtype: bool ""...原创 2016-08-15 00:10:27 · 129 阅读 · 0 评论 -
Power of Three——Math
Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion?class Solution(object): def isPowerOfThree(self, ...原创 2016-08-15 00:11:01 · 143 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree——Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee...原创 2016-08-15 00:12:13 · 133 阅读 · 0 评论 -
Number of 1 Bits——Bit Manipulation
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 00000000...原创 2016-08-15 00:13:58 · 129 阅读 · 0 评论 -
Happy Number——Math
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares...原创 2016-08-15 00:14:18 · 162 阅读 · 0 评论 -
Remove Duplicates from Sorted List——Linked List
Given 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.# ...原创 2016-08-17 20:44:28 · 133 阅读 · 0 评论 -
Ugly Number——Math
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since ...原创 2016-08-17 20:46:39 · 127 阅读 · 0 评论 -
Climbing Stairs——Dynamic Programming
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?class Solution(object): d...原创 2016-08-17 20:46:49 · 128 阅读 · 0 评论 -
Factorial Trailing Zeroes——Math
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.class Solution(object): def trailingZeroes(self, n): """...原创 2016-08-17 21:09:48 · 138 阅读 · 0 评论 -
Valid Anagram——Hash Table
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.class Solution(object):...原创 2016-08-13 20:59:48 · 149 阅读 · 0 评论 -
Same Tree——Depth-first Search
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.# Definition ...原创 2016-08-12 21:42:03 · 168 阅读 · 0 评论 -
Merge Sorted Array——Array
Given 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) to hold addition...原创 2016-08-10 16:16:48 · 292 阅读 · 0 评论 -
Two Sum——Array
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example: Given nums = [...原创 2016-08-10 16:17:15 · 127 阅读 · 0 评论 -
Contains Duplicate——Array
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 ...原创 2016-08-10 16:19:57 · 99 阅读 · 0 评论 -
Contains Duplicate II——Array
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.class ...原创 2016-08-10 16:24:24 · 113 阅读 · 0 评论 -
Reverse String——String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".class Solution(object): def reverseString(self, s): """ ...原创 2016-08-11 16:23:07 · 165 阅读 · 0 评论 -
Sum of Two Integers——Bit Manipulation
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3. class Solution(object): def getSum(self, a, b): ...原创 2016-08-11 16:23:15 · 98 阅读 · 0 评论 -
Nim Game——Brainteaser
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 th...原创 2016-08-11 16:24:32 · 159 阅读 · 0 评论 -
Add Digits——Math
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one di...原创 2016-08-11 16:26:45 · 132 阅读 · 0 评论 -
Maximum Depth of Binary Tree——Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. # Definition for a binary tree nod...原创 2016-08-11 16:27:52 · 106 阅读 · 0 评论 -
Invert Binary Tree——Tree
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(objec...原创 2016-08-12 21:30:53 · 178 阅读 · 0 评论 -
Move Zeroes——Two Pointers
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 f...原创 2016-08-12 21:35:15 · 154 阅读 · 0 评论 -
Delete Node in a Linked List——Link list
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 wi...原创 2016-08-12 21:39:28 · 117 阅读 · 0 评论 -
Intersection of Two Arrays——Array
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, nums2):...原创 2016-08-12 21:40:24 · 157 阅读 · 0 评论 -
Binary Tree Level Order Traversal——Breadth-first Search
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20...原创 2016-08-17 21:12:11 · 226 阅读 · 0 评论