
LeetCode
坚持,说起来容易,做起来真难!
. . . . .
越努力越幸运!
展开
-
Valid Parentheses
题目链接Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type ...原创 2019-02-01 16:20:29 · 1031 阅读 · 0 评论 -
Pascal's Triangle
题目链接Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Example:Input: 5Output...原创 2019-02-01 11:58:38 · 265 阅读 · 0 评论 -
Reverse Bits
Reverse bits of a given 32 bits unsigned integer.Example 1:Input: 00000010100101000001111010011100Output: 00111001011110000010100101000000Explanation: The input binary string 00000010100101000001...原创 2019-01-31 20:42:08 · 364 阅读 · 1 评论 -
Hamming Distance
The 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 < 231....原创 2019-01-31 19:03:39 · 552 阅读 · 0 评论 -
Number of 1 Bits
题目链接Write a function that takes an unsigned integer and return the number of ‘1’ bits it has (also known as the Hamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanat...原创 2019-01-31 18:13:48 · 285 阅读 · 0 评论 -
Roman to Integer
题目链接Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-01-30 18:41:25 · 185 阅读 · 0 评论 -
Count Primes
题目链接Count the number of prime numbers less than a non-negative number, n.Example:Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.看似不屑一顾的题目,却踩了大坑pyth...原创 2019-01-23 21:55:50 · 546 阅读 · 0 评论 -
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”...原创 2019-01-22 23:10:40 · 154 阅读 · 0 评论 -
Min Stack
题目链接Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack.pop() – Removes the element on top of the stack.top() – Ge...原创 2019-01-21 20:40:35 · 177 阅读 · 0 评论 -
Shuffle an Array
题目链接Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3.int[] nums = {1,2,3};Solution solution = new Solution(nums);// Shuffle the array [1,2,3] and return...原创 2019-01-21 19:36:49 · 317 阅读 · 0 评论 -
House Robber
题目链接You 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 adjacent ...原创 2019-01-21 18:37:33 · 395 阅读 · 1 评论 -
Maximum Subarray && 动态规划详解
题目链接Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explan...原创 2019-01-21 16:26:34 · 780 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
题目链接Say 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 (i.e., buy one and sell one share of the sto...原创 2019-01-20 23:01:36 · 146 阅读 · 0 评论 -
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 posit...原创 2019-01-08 23:24:46 · 216 阅读 · 0 评论 -
First Bad Version
题目链接You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based o...原创 2019-01-07 16:04:35 · 223 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
题目链接Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of...原创 2019-01-04 09:24:51 · 170 阅读 · 0 评论 -
Binary Tree Level Order Traversal
题目链接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/&...原创 2019-01-02 10:40:08 · 218 阅读 · 0 评论 -
Symmetric Tree
题目链接Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:1/ \2 2/\ \ /\ 3 4 4 3But the...原创 2018-12-28 15:39:47 · 280 阅读 · 3 评论 -
Validate Binary Search Tree
题目链接Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.T...原创 2018-12-27 16:55:33 · 210 阅读 · 0 评论 -
Merge Two Sorted Lists
题目链接Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output:...原创 2018-12-21 21:04:50 · 144 阅读 · 0 评论 -
Reverse Linked List
题目链接Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recurs...原创 2018-12-20 22:01:14 · 132 阅读 · 0 评论 -
Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the ...原创 2018-12-20 21:52:10 · 194 阅读 · 0 评论 -
Delete Node in a Linked List
题目链接Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list – head = [4,5,1,9], which looks like following:4 -> 5 -> 1 -&...原创 2018-12-19 16:57:33 · 162 阅读 · 0 评论 -
Longest Common Prefix
题目链接Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string “”.Example 1:Input: [“flower”,“flow”,“flight”]Outpu...原创 2018-12-17 22:17:31 · 127 阅读 · 0 评论 -
Valid Palindrome
题目链接Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note:For the purpose of this problem, we define empty string as valid palindrome.E...原创 2018-12-11 16:30:49 · 136 阅读 · 0 评论 -
Valid Anagram
题目链接Given two strings s and t , write a function to determine if t is an anagram of s.Example 1:Input: s = “anagram”, t = “nagaram”Output: trueExample 2:Input: s = “rat”, t = “car”Output: fa...原创 2018-12-10 13:13:28 · 141 阅读 · 0 评论 -
First Unique Character in a String
题目链接Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Examples:s = “leetcode”return 0.s = “loveleetcode”,return 2.Note:You ma...原创 2018-12-06 11:21:38 · 181 阅读 · 0 评论 -
Valid Sudoku
题目链接Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must c...原创 2018-12-03 20:25:12 · 355 阅读 · 0 评论 -
Two Sum
题目链接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, and you may not use the s...原创 2018-11-30 13:25:03 · 152 阅读 · 0 评论 -
Move Zeroes
题目链接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.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You...原创 2018-11-29 21:26:44 · 123 阅读 · 0 评论 -
8. String to Integer (atoi)
题目链接import reclass Solution: def myAtoi(self, str): # 首先取出字符前面的空格 str2 = str for index, item in enumerate(str): if item == ' ': str2 = str[i...原创 2018-11-19 23:32:14 · 154 阅读 · 0 评论 -
华为上机迷宫问题
题目描述定义一个二维数组N*M(其中2<=N<=10;2<=M<=10),如5 × 5数组下所示:int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,};它表示一个迷宫,其中的1表示墙...原创 2018-09-19 20:48:29 · 490 阅读 · 0 评论 -
统计字符
题目描述给定一个英文字符串,请写一段代码找出这个字符串中首先出现三次的那个英文字符(需要区分大小写)。输入描述:输入数据一个字符串,包括字母,数字等。输出描述:输出首先出现三次的那个英文字符示例1输入Have you ever gone shopping and输出e代码实现:string = input()i = 0while i&lt;len(string):...原创 2018-09-19 20:44:31 · 271 阅读 · 0 评论 -
句子翻转
题目描述给定一个句子(只包含字母和空格), 将句子中的单词位置反转,单词用空格分割, 单词之间只有一个空格,前后没有空格。 比如: (1) “hello xiao mi”-&gt; “mi xiao hello”输入描述:输入数据有多组,每组占一行,包含一个句子(句子长度小于1000个字符)输出描述:对于每个测试示例,要求输出句子中单词反转后形成的句子示例1输入hello xiao...原创 2018-09-19 20:41:26 · 617 阅读 · 0 评论 -
电话号码分身
题目描述继MIUI8推出手机分身功能之后,MIUI9计划推出一个电话号码分身的功能:首先将电话号码中的每个数字加上8取个位,然后使用对应的大写字母代替 (“ZERO”, “ONE”, “TWO”, “THREE”, “FOUR”, “FIVE”, “SIX”, “SEVEN”, “EIGHT”, “NINE”), 然后随机打乱这些字母,所生成的字符串即为电话号码对应的分身。输入描述:第一行是...原创 2018-09-19 20:38:26 · 549 阅读 · 0 评论 -
数串
题目描述设有n个正整数,将他们连接成一排,组成一个最大的多位整数。如:n=3时,3个整数13,312,343,连成的最大整数为34331213。如:n=4时,4个整数7,13,4,246连接成的最大整数为7424613。输入描述:有多组测试样例,每组测试样例包含两行,第一行为一个整数N(N&lt;=100),第二行包含N个数(每个数不超过1000,空格分开)。输出描述:每组数据输出一...原创 2018-09-19 20:34:24 · 184 阅读 · 0 评论