- 博客(29)
- 收藏
- 关注
原创 [LeetCode] Divide Two Integers
题目Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路这道题需要用到移位操作,这就涉及到一些二进制相关的概念,先普及一下:1)二进制表示中,首位是符号位,1表示复数,0表示正数2)二进制表示
2016-01-05 10:08:05
350
原创 [LeetCode] Implement strStr()
题目Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路按照下标递增的顺序比较haystack中的所有子字符串和needle。代码public class Solu
2016-01-05 10:04:09
282
原创 [LeetCode] Remove Element
题目Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length
2016-01-05 09:57:52
267
原创 [LeetCode] Remove Duplicates from Sorted Array
题目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 pl
2016-01-04 20:18:52
248
原创 [LeetCode] Reverse Nodes in k-Group
题目Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain
2016-01-04 20:12:49
264
原创 [LeetCode] 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
2016-01-04 20:05:00
251
原创 [LeetCode] Regular Expression Matching
题目Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire
2016-01-04 19:57:05
262
原创 [LeetCode] Merge k 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.思路考察的是Two Pointers思想。开始这两个指针分别指向两个链表的头节点,每次取出这两
2016-01-04 19:47:28
234
原创 [LeetCode] Generate Parentheses
题目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-01-04 19:37:50
271
原创 [LeetCode] 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.思路这道题比较简单,直接上代码。代码/** * Definition for sin
2015-12-08 16:37:06
323
原创 [LeetCode] 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
2015-12-08 16:29:49
253
原创 [LeetCode] Remove Nth Node From End of List
题目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 the
2015-12-08 16:24:03
380
原创 [Leetcode] 4Sum
题目Given anarray S of n integers, are thereelements a, b, c, and d in S suchthat a + b + c + d = target? Find allunique quadruplets in the array which gives the sum of target.Note:Elements in a
2015-12-08 16:21:43
291
原创 [LeetCode] Letter Combinations of a Phone Number
题目Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:
2015-11-30 22:25:48
351
原创 [LeetCode] 3Sum Closest
题目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 would have
2015-11-25 11:51:28
295
原创 [LeetCode] 3Sum
题目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:Elements in a triple
2015-11-20 15:38:15
298
原创 [LeetCode] Longest Common Prefix
题目Write a function to find the longest common prefix string among an array of strings.Subscribe to see which companies asked this question思路最长前缀,显然不可能比数组中任意一个字符串长。除去数组为空的特殊情况,选中第一个字符
2015-11-20 15:28:27
398
原创 [LeetCode] Roman to Integer
问题Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Subscribe to see which companies asked this question思路罗马数字的构造方式上一篇博客里面
2015-11-20 14:55:34
273
原创 [LeetCode] Integer to Roman
题目Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路首先需要了解罗马数字的构造规律:罗马数字共有七个,即I(1),V(5),X(10),L(50),C(100),D(500),M(1000)。按照
2015-11-16 14:29:54
326
原创 [LeetCode] Container With Most Water
题目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) and (
2015-11-16 13:19:56
319
原创 [LeetCode] Palindrome Number
题目Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of
2015-11-11 13:49:46
252
原创 [LeetCode] 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
2015-11-10 17:55:45
313
原创 [LeetCode] Reverse Integer
题目Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask
2015-11-10 16:28:42
407
原创 [LeetCode] 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
2015-11-10 15:14:24
463
原创 [LeetCode] Longest Palindromic Substring
题目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.思路1最直接的思
2015-11-09 20:44:31
273
原创 [LeetCode] Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).思路题目中已经给出了时间复杂度的要
2015-11-04 15:25:05
381
原创 [LeetCode] Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is
2015-11-04 12:26:27
343
原创 [LeetCode] Add Two Numbers
题目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 it a
2015-11-03 17:04:00
373
原创 [LeetCode] Two Sum
题目Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the t
2015-11-03 16:59:54
272
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人