
leetcode
文章平均质量分 64
Dufre.WC
厚积薄发
展开
-
leetcode No336. Palindrome Pairs
QuestionGiven a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.Example 1:Inp...原创 2020-04-05 15:15:05 · 352 阅读 · 0 评论 -
leetcode No315. Count of Smaller Numbers After Self
QuestionYou are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Exa...原创 2020-03-03 14:29:29 · 412 阅读 · 0 评论 -
leetcodeNo743. Network Delay Time
Question743. Network Delay TimeThere are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target nod...原创 2020-02-25 22:59:34 · 271 阅读 · 0 评论 -
leetcode No617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree....原创 2020-01-07 18:25:07 · 225 阅读 · 0 评论 -
leetcode No369. Plus One Linked List
QuestionGiven a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 ...原创 2020-01-03 00:18:09 · 243 阅读 · 0 评论 -
leetcode No593. Valid Square
QuestionGiven the coordinates of four points in 2D space, return whether the four points could construct a square.The coordinate (x,y) of a point is represented by an integer array with two integers...原创 2019-12-31 16:32:04 · 252 阅读 · 0 评论 -
leetcode No283. Move Zeroes
QuestionGiven 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]Algori...原创 2019-12-31 16:02:43 · 223 阅读 · 1 评论 -
leetcode No557. Reverse Words in a String III
QuestionGiven 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 con...原创 2019-12-25 17:08:20 · 205 阅读 · 0 评论 -
leetcode No1114. Print in Order
QuestionSuppose we have a class:public class Foo { public void first() { print("first"); } public void second() { print("second"); } public void third() { print("third"); }}The same instanc...原创 2019-12-27 10:08:50 · 284 阅读 · 0 评论 -
leetcode No389. Find the Difference
QuestionGiven 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 w...原创 2019-12-19 19:05:55 · 266 阅读 · 0 评论 -
leetcode No292. Nim Game
Question: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 st原创 2016-05-16 20:46:38 · 835 阅读 · 0 评论 -
leetcode No258. Add Digits
Question: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. S原创 2016-05-16 20:52:04 · 896 阅读 · 0 评论 -
leetcode No344.Reverse String Note
Question:Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".算法:(1)复制一个字符串 (2)逆序给原来的字符串class Solution {public:原创 2016-05-16 20:40:57 · 742 阅读 · 0 评论 -
leetcode No26. Remove Duplicates from Sorted Array
Question:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place...原创 2016-05-16 21:12:27 · 568 阅读 · 0 评论 -
leetcode No9. Palindrome Number
Question:Determine whether an integer is a palindrome. Do this without extra space.判断一个整数是否为回文数,回文数是把整数n的各位数字反向排列所得数与n相等。Algorithm:把n的各位数字反向排列得到的数和n相等即是回文数Submitted Code:class Soluti原创 2016-06-11 17:21:11 · 563 阅读 · 0 评论 -
leetcode No201. Bitwise AND of Numbers Range
Question:Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.即把在 m Algorithm:Bit Manipulation我们不妨先举几个例子:1、m=5(1001),n=5(1001);m-n=0 return 5(1原创 2016-06-06 21:03:33 · 446 阅读 · 0 评论 -
leetcode No13. Roman to Integer
前言:先说点背景吧,这题我一直放着没做,因为我不知道Roman数是怎么计数的呀,然后最近在看《数学之美》(特别有意思的书,第一次觉得数学还挺有意思的)罗马人也是用不同的符号代表数的不同量级。Symbol ValueI 1V 5X 10L原创 2016-06-13 11:22:28 · 583 阅读 · 0 评论 -
leetcode No39. Combination Sum
Question:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C u原创 2016-07-11 17:41:38 · 496 阅读 · 0 评论 -
leetcode No40. Combination Sum II
Question:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums toT.Each number in C may only be used once原创 2016-07-11 17:46:41 · 599 阅读 · 0 评论 -
leetcode No2. Add Two Numbers
Question:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return原创 2016-06-15 09:25:23 · 591 阅读 · 0 评论 -
leetcode No5. Longest Palindromic Substring
Question:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.题目大意是找出原创 2016-06-15 11:41:22 · 477 阅读 · 0 评论 -
leetcode No6. ZigZag Conversion
Question: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原创 2016-06-15 16:28:11 · 616 阅读 · 0 评论 -
leetcode No11. Container With Most Water
Question:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) an原创 2016-06-15 17:54:46 · 558 阅读 · 0 评论 -
leetcode No19. Remove Nth Node From End of List
Question:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from原创 2016-07-02 20:31:53 · 441 阅读 · 0 评论 -
leetcode No8. String to Integer (atoi)
Question: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 poss原创 2016-06-17 11:13:39 · 447 阅读 · 0 评论 -
leetcode No22. Generate Parentheses
Question:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())(原创 2016-07-03 21:55:17 · 582 阅读 · 0 评论 -
leetcode No24. Swap Nodes in Pairs
Question: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 cons原创 2016-07-04 21:37:31 · 435 阅读 · 0 评论 -
leetcode No27. Remove Element
Question: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 constan原创 2016-07-05 20:38:50 · 416 阅读 · 0 评论 -
leetcode No51. N-Queens
Question:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-qu原创 2016-07-16 16:06:55 · 489 阅读 · 0 评论 -
leetcode No37. Sudoku Solver
Question:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sud原创 2016-07-17 10:16:28 · 566 阅读 · 0 评论 -
leetcode No28. Implement strStr()
Question:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题目大意就是在字符串haystack中有没有字符串needle,如果有返回下标,如果没有返回-1Alg原创 2016-07-07 10:42:19 · 409 阅读 · 0 评论 -
leetcode No29. Divide Two Integers
Question:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题目大意就是不用乘法算两个数相除的结果Algorithm:用语言描述有点说不清楚。。。。举个例子,65/9=(36原创 2016-07-07 11:33:20 · 416 阅读 · 0 评论 -
leetcode No12. Integer to Roman
Question:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.原创 2016-06-21 19:58:15 · 459 阅读 · 0 评论 -
leetcode No35. Search Insert Position
Question: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 duplicate原创 2016-07-07 19:03:21 · 413 阅读 · 0 评论 -
leetcode No50. Pow(x, n)
Question:Implement pow(x, n).Algorithm:举个例子:假如是3的35次方,35=2^5+2^1+2^0,要注意超出INT_MAX的情况Accepted Code:class Solution {public: double myPow(double x, int n) { if(n==0)return 1;原创 2016-07-28 16:27:41 · 460 阅读 · 0 评论 -
leetcode No53. Maximum Subarray
Question:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray原创 2016-07-28 16:46:50 · 533 阅读 · 0 评论 -
leetcode No36. Valid Sudoku
Question:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.原创 2016-07-07 19:55:34 · 565 阅读 · 0 评论 -
leetcode No14. Longest Common Prefix
Question:Write a function to find the longest common prefix string amongst an array of strings.大意即是求字符串组的最长公共前缀Ex:vector strs={"abc","abcd","abcdef"};那么最长公共前缀即"abc";Algorithm:先找出最小长度的字符串长度原创 2016-06-21 20:13:03 · 413 阅读 · 0 评论 -
leetcode No15. 3Sum
Question:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set mus原创 2016-06-22 21:05:59 · 525 阅读 · 0 评论 -
leetcode No16. 3Sum Closest
Question:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input wou原创 2016-06-22 21:16:47 · 462 阅读 · 0 评论