LeetCode OJ
文章平均质量分 52
灵感来于瞬息之间
这个作者很懒,什么都没留下…
展开
-
LeetCode OJ-13-Roman to Integer
题目:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.大意:给定一个罗马数字,将其转换成对应的整数。 输入的数字在1-3999之间。思路:根据罗马数字与整数的对应关系进行加减法操作,从低位向高位计算,若高位比低位的数字小则减转载 2016-09-11 23:49:26 · 302 阅读 · 0 评论 -
LeetCode OJ-41-First Missing Positive
题目:Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant s原创 2016-10-12 17:33:05 · 231 阅读 · 0 评论 -
LeetCode OJ-43-Multiply Strings
题目:Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. Converting the input string to integer原创 2016-10-13 12:06:42 · 215 阅读 · 0 评论 -
LeetCode OJ-42-Trapping Rain Water
题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,原创 2016-10-13 10:20:20 · 211 阅读 · 0 评论 -
LeetCode OJ-44-Permutations
题目:Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3转载 2016-10-13 17:15:13 · 226 阅读 · 0 评论 -
LeetCode OJ-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. You原创 2016-09-27 16:08:28 · 269 阅读 · 0 评论 -
LeetCode OJ-26-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 place with原创 2016-09-28 17:03:22 · 185 阅读 · 0 评论 -
LeetCode OJ-27-Remove Element
题目: 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 constant memory.原创 2016-09-28 17:15:27 · 194 阅读 · 0 评论 -
LeetCode OJ-28-Implement strStr()
题目:Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.大意:实现实现strStr()函数,判断一个字符串在另一个字符串中出现的位置。如果不匹配就返回-1。思路:找到needle首字母在haystac原创 2016-09-28 17:25:33 · 214 阅读 · 0 评论 -
LeetCode OJ-31-Next Permutation
题目:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible原创 2016-09-29 14:09:06 · 246 阅读 · 0 评论 -
LeetCode OJ-34-Search for a Range
题目:Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not found in原创 2016-09-30 11:15:59 · 240 阅读 · 0 评论 -
LeetCode OJ-23-Merge k Sorted Lists
题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.大意: 合并k个排好的的单链表。分析和描述它的复杂性。思路: 使用小顶堆来实现,先将K个链表的头结点入堆,取堆顶元素,这个结点就是最小的,接着让取出的这个结点的下一个结点入堆,再取堆顶元素,其原创 2016-09-26 14:28:17 · 210 阅读 · 0 评论 -
LeetCode OJ-40-Combination Sum II
题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combina原创 2016-10-11 20:44:33 · 264 阅读 · 0 评论 -
LeetCode OJ-22-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-09-22 17:12:36 · 337 阅读 · 0 评论 -
LeetCode OJ-14-Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.大意:写一个函数找出一个字符串数组中的最长的公共前缀。思路:采用OJ给出的前三种方法。 方法1:宽度扫描。设字符串数组的长度为prefix,将prefix的值初始化为数组的第一个元素,从数组的第二个元素开始利用indexO原创 2016-09-12 14:42:58 · 262 阅读 · 0 评论 -
LeetCode OJ-15-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. For example, given array S = [-1, 0, 1, 2原创 2016-09-18 21:35:04 · 194 阅读 · 0 评论 -
LeetCode OJ-16-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 exa转载 2016-09-19 10:18:17 · 202 阅读 · 0 评论 -
LeetCode OJ-17-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:Digit string转载 2016-09-19 16:22:41 · 265 阅读 · 0 评论 -
LeetCode OJ-18-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.For example, given arr转载 2016-09-20 11:42:13 · 219 阅读 · 0 评论 -
LeetCode OJ-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-10-10 10:03:57 · 195 阅读 · 0 评论 -
LeetCode OJ-36-Valid Sudoku
题目: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 ‘.’. A partially filled sudo原创 2016-10-10 11:47:59 · 178 阅读 · 0 评论 -
LeetCode OJ-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 1s” or 21. 21 is read off as “one 2,原创 2016-10-10 15:26:02 · 315 阅读 · 0 评论 -
LeetCode OJ-39-Combination Sum
题目: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 unlimited number原创 2016-10-10 21:33:46 · 229 阅读 · 0 评论 -
LeetCode OJ-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 valid原创 2016-09-22 11:54:20 · 182 阅读 · 0 评论 -
LeetCode OJ-48-Rotate Image
题目:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).大意:n×n二维矩阵顺时针旋转90°,求旋转后的数组。思路:找到 matrix[i][j] = matrix[n-1-j][i] 的规律。代码:public class Solution {原创 2016-10-18 11:43:56 · 308 阅读 · 0 评论