![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode刷题
自行车454
这个作者很懒,什么都没留下…
展开
-
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 target, whe...原创 2015-02-09 22:55:32 · 84 阅读 · 0 评论 -
Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.这个和之前的相比就是倒序一下[code="java"] public int romanToInt(String s) { int result = 0...2015-03-03 22:20:37 · 77 阅读 · 0 评论 -
Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.额,这个暴力点就成[code="java"] public String longestCommonPrefix(String[] strs) { String result = ""; ...2015-03-03 22:21:58 · 76 阅读 · 0 评论 -
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 triplet (a,b,c) must...2015-03-03 22:34:24 · 92 阅读 · 0 评论 -
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 exactly...原创 2015-03-05 22:25:24 · 73 阅读 · 0 评论 -
4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a...原创 2015-03-05 22:26:36 · 64 阅读 · 0 评论 -
Letter Combinations of a Phone Number
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 butt...2015-03-05 22:30:11 · 104 阅读 · 0 评论 -
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 end,...2015-03-05 22:31:31 · 90 阅读 · 0 评论 -
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 valid ...2015-03-05 22:33:52 · 86 阅读 · 0 评论 -
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:"((()))", "(()())", "(())()", "()(())", "()()...2015-03-12 19:50:22 · 91 阅读 · 0 评论 -
Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.数字转换为罗马数字,而且还限制了最大值,所以用一个很取巧的方式。[code="java"] public String intToRoman(int num) ...原创 2015-03-01 23:35:29 · 67 阅读 · 0 评论 -
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 (i, 0). Find two ...2015-03-01 22:55:58 · 62 阅读 · 0 评论 -
Median of Two Sorted Arrays
There are two sorted arrays A and B 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-02-10 23:12:19 · 64 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
[size=24px;]Longest Substring Without Repeating Characters[/size] Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without ...原创 2015-02-11 21:14:57 · 76 阅读 · 0 评论 -
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 as a link...原创 2015-02-12 22:12:55 · 73 阅读 · 0 评论 -
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.寻找最长的回文字符串。用的是一个比较简单的方式。...原创 2015-02-12 22:50:07 · 79 阅读 · 0 评论 -
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-02-12 23:37:07 · 76 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.这题挺简单的,我用了一个比较取巧的方式。效率不会太高。可以用普通的方式来做,那样效率会高很多。public class Solution { ...原创 2015-02-12 23:39:38 · 80 阅读 · 0 评论 -
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-02-13 11:07:12 · 89 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.判断是否为回文数,比较简单,可以用两种方式做,一种是用java中的stringbuffer的一个反转函数,一种直接判断数字。后一种效率比较高。前者代码量少点。1:public class Solution { public boo...2015-02-13 22:08:03 · 73 阅读 · 0 评论 -
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 inp...2015-03-01 20:19:24 · 75 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.这题我写的太难看了,就直接看网上copy下来的吧,具体是哪里copy过来的我忘记了。几天的思想就是分治。[code="java"]/** * Definition for singly-lin...2015-03-12 19:55:46 · 78 阅读 · 0 评论