![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 60
judadeshu
邮箱:judadeshu@live.com
展开
-
LeetCode 292: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 t原创 2015-12-11 18:10:42 · 232 阅读 · 0 评论 -
LeetCode 14:Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.找出一组给定字符串的最长共同前缀。这个最长共同前缀不是指两个字符串之间的,而是指所有字符串的最长共同前缀,例如给定str1 = "abcd" , str2 = "abc" , str3 = "ab" , st原创 2015-12-21 21:05:48 · 248 阅读 · 0 评论 -
LeetCode 8:String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2015-12-21 22:50:32 · 315 阅读 · 0 评论 -
LeetCode 260:Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given原创 2016-01-22 17:27:58 · 254 阅读 · 0 评论 -
LeetCode 165:Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2015-12-22 13:47:18 · 299 阅读 · 0 评论 -
LeetCode 6:ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2015-12-22 20:14:32 · 217 阅读 · 0 评论 -
LeetCode 9:Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2016-01-24 17:27:46 · 280 阅读 · 0 评论 -
LeetCode 38:Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1" or 21.21 is read off as "原创 2015-12-23 15:09:25 · 208 阅读 · 0 评论 -
LeetCode 228:Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].给定一个没有重复数字的数组,返回它的范围。例如,给定数组[0,1,2,4,5,7] ,应当返回["原创 2015-12-24 08:34:15 · 246 阅读 · 0 评论 -
LeetCode 125:Valid Palindrome
Given 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" is not a原创 2015-12-21 19:17:11 · 255 阅读 · 0 评论 -
LeetCode 234:Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?给定一个单链表,判断单链表是否回文。进阶:你能只用O(n)的时间复杂度和O(1)的空间复杂度吗?题目不难,可是我想了很久都只能做到O(n)的原创 2015-12-21 19:03:14 · 247 阅读 · 0 评论 -
LeetCode 168:Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 不翻译了,就是17原创 2015-12-19 17:03:37 · 221 阅读 · 0 评论 -
LeetCode 189:Rotate Array
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,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as yo原创 2015-12-19 20:44:33 · 190 阅读 · 0 评论 -
LeetCode 67:Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".给定两个二进制字符串,返回他们的和(也用二进制表示)例如a = 11,b = 1,应当返回 100为什么这道题写得这么丑,因为我用了大量的复制粘贴,原创 2015-12-20 01:29:29 · 230 阅读 · 0 评论 -
LeetCode 203:Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5移除单链表中所有值为val的节点。例如:给定1原创 2015-12-20 15:57:23 · 217 阅读 · 0 评论 -
LeetCode 290:Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2015-12-20 18:04:46 · 432 阅读 · 0 评论 -
LeetCode 219:Contains Duplicate II
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 jis at most k.原创 2015-12-20 22:26:46 · 265 阅读 · 0 评论 -
LeetCode 299:Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2015-12-20 23:14:06 · 394 阅读 · 0 评论 -
LeetCode 119:Pascal's Triangle II
Given 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?给定一个整数k,返回帕斯卡三原创 2015-12-21 00:27:28 · 234 阅读 · 0 评论 -
LeetCode 223:Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2015-12-24 10:35:02 · 286 阅读 · 0 评论 -
LeetCode 238:Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O原创 2016-01-26 02:09:18 · 230 阅读 · 0 评论 -
LeetCode 1: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.Example:Given nums =原创 2016-05-22 22:01:41 · 210 阅读 · 0 评论 -
LeetCode 345:Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".翻转一个字符原创 2016-05-23 20:29:50 · 237 阅读 · 0 评论 -
LeetCode 389: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原创 2016-09-12 20:04:52 · 263 阅读 · 0 评论 -
LeetCode 374:Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is h原创 2016-09-13 16:34:20 · 316 阅读 · 0 评论 -
LeetCode 24:Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2016-09-13 20:26:20 · 228 阅读 · 0 评论 -
LeetCode 387: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:原创 2016-09-13 21:03:25 · 210 阅读 · 0 评论 -
LeetCode 383:Ransom Note
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 constru原创 2016-09-12 20:00:29 · 288 阅读 · 0 评论 -
LeetCode 278: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 on the原创 2017-02-24 22:07:40 · 187 阅读 · 0 评论 -
LeetCode 344:Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".编写一个翻转字符串的函数。例如:给定字符串 s = "hello" 返回"ollea"挺简单的,没啥说的吧。。。clas原创 2016-05-22 21:57:23 · 253 阅读 · 0 评论 -
LeetCode 350:Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma原创 2016-05-24 11:36:30 · 324 阅读 · 0 评论 -
LeetCode 101:Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2016-01-30 15:55:17 · 203 阅读 · 0 评论 -
LeetCode 160:Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2016-01-30 18:47:47 · 293 阅读 · 0 评论 -
LeetCode 20:Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2015-12-20 00:42:33 · 242 阅读 · 0 评论 -
LeetCode 303:Range Sum Query - Immutable
Given 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) -> -1sumRan原创 2016-01-30 23:49:34 · 222 阅读 · 0 评论 -
LeetCode 144:Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2016-01-31 00:27:18 · 220 阅读 · 0 评论 -
LeetCode 35:Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2016-02-03 23:21:49 · 253 阅读 · 0 评论 -
LeetCode 94:Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2016-02-29 13:47:06 · 206 阅读 · 0 评论 -
LeetCode 141:Linked List Cycle 官方解答翻译
Question Code it now!Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?SolutionHash table – O(n)O(n) time,翻译 2016-03-14 21:42:15 · 471 阅读 · 0 评论 -
LeetCode 155: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() -- Get原创 2015-12-19 16:10:41 · 308 阅读 · 0 评论