
LeetCode
Jay__Feng
欲速则不达,达则兼济天下。
展开
-
四元组相加获得target
四元组相加获得target4Sum给定一个数组,选择四个元素相加,结果为target,找出所有符合的四元组。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原创 2017-06-30 11:41:44 · 392 阅读 · 0 评论 -
三元组相加获得结果最接近target
三元组相加获得结果最接近target3SumClosest给定一个数组,选择三个元素相加,结果必须为所有三元组中最接近target的值,返回这个三元组的和Given an array S of n integers, find three integers in S such that the sum is closest to a given number: target.Return th原创 2017-06-27 11:40:39 · 467 阅读 · 0 评论 -
验证大小中括号是否成对闭合匹配
验证大小中括号是否成对闭合匹配Valid Parentheses验证大小中括号是否成对闭合匹配。Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the c原创 2017-06-30 11:55:50 · 1595 阅读 · 0 评论 -
移除链表倒数第n个元素
移除链表倒数第n个元素Remove Nth Node From End of List给定一个链表,移除倒数第n个元素,返回链表头部。Given a linked list, remove the nth node from the end of list and return its head.Note: Given n will always be valid. Try to do t原创 2017-06-30 11:54:52 · 269 阅读 · 0 评论 -
合并两个已排序的链表
合并两个已排序的链表Valid Parentheses合并两个已排序的链表,新链表中的每个节点必须是来自输入的两个链表的节点(即不能构造新的节点),返回新链表的头部。Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the node原创 2017-06-30 14:22:49 · 296 阅读 · 0 评论 -
手动实现.*正则表达式匹配函数
手动实现简单正则表达式匹配函数regular expression matching'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).Some exa原创 2017-06-18 00:33:48 · 1448 阅读 · 0 评论 -
九宫格键盘输入
九宫格键盘输入Letter Combinations of a Phone Number给定一个数字字符串,返回数字可能代表的所有可能的字母组合。数字到字母的映射(就像九宫格电话按钮一样)如下图。 Given a digit string, return all possible letter combinations that the number could represent.A map原创 2017-06-28 14:20:44 · 7799 阅读 · 0 评论 -
构造n个成对括号
构造n个成对括号Generate Parentheses给出一个整数n,实现一个函数生成n对小括号,n对小括号的左右括弧顺序不限,但应该闭合。Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.example 1For example, gi原创 2017-07-19 09:30:34 · 426 阅读 · 0 评论 -
k组倒置链表节点
k组倒置链表节点Reverse Nodes in k-Group给定一个链表,每k个倒置其节点,返回新链表的头部,不允许使用额外的内存,只能在原有链表节点基础上进行操作。题目原文:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a pos原创 2017-07-31 18:00:57 · 345 阅读 · 0 评论 -
合并n个已排序的链表
合并n个已排序的链表Merge k Sorted Lists合并n个已排序的链表,新链表中的每个节点必须是来自输入的原链表的节点(即不能构造新的节点),返回新链表的头部。Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.example 1input:原创 2017-07-19 16:43:06 · 411 阅读 · 0 评论 -
移除数组中的重复元素
移除数组中的重复元素Remove Duplicates from Sorted Array给定一个数组,移除数组中的重复元素,返回新数组的长度,不允许开辟新的数组空间,只能在原数组内存中完成。题目原文:Given a sorted array, remove the duplicates in place such that each element appear only once and原创 2017-08-01 16:34:24 · 680 阅读 · 1 评论 -
成对交换链表节点
成对交换链表节点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 retu原创 2017-07-25 18:51:19 · 895 阅读 · 0 评论 -
三元组相加获得target
三元组相加获得target3Sum给定一个数组,选择三个元素相加,结果为target,找出所有符合的三元组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原创 2017-06-27 11:32:14 · 479 阅读 · 0 评论 -
字符串数组最长公共前缀
字符串数组最长公共前缀Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.example 1input: ['asdqowi','asdb', 'asdmnc']output: 'asd'思路i从0开始自增,判断每个字符串 i 位置原创 2017-06-23 16:39:04 · 4822 阅读 · 0 评论 -
罗马数字转换成阿拉伯数字
罗马数字转换成阿拉伯数字Roman to integerGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.example 1input: CCCLXXXIXoutput: 389思路dict存储单个罗马字母代表的阿拉伯数字初始原创 2017-06-23 12:46:44 · 1364 阅读 · 0 评论 -
寻找最长不重复子串
寻找最长不重复子串Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the原创 2017-06-04 11:42:21 · 366 阅读 · 0 评论 -
查询两个数组的中位数
查询两个数组的中位数Median of Two Sorted ArraysThere 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原创 2017-06-04 11:50:20 · 374 阅读 · 0 评论 -
查找字符串最长回文
查找字符串最长回文Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: “a原创 2017-06-04 13:26:08 · 680 阅读 · 0 评论 -
实现atoi函数(string转integer)
实现atoi函数(string转integer)String to Integer (atoi)Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. Notes: It is intended for this problem to be speci原创 2017-06-12 22:56:47 · 618 阅读 · 0 评论 -
不使用任何额外变量判断回文数字(6行代码)
不使用任何额外变量判断回文数字Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.Notes: any negative number is not palindrome.Example 1:Input: 1221Output: TrueExample 2:原创 2017-06-12 23:24:17 · 352 阅读 · 0 评论 -
合并两棵二叉树(7 lines)
合并两棵二叉树Merge Two Binary TreesGiven 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原创 2017-06-13 10:31:15 · 871 阅读 · 0 评论 -
两个链表数字相加
两个链表数字相加Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the t原创 2017-06-19 17:08:54 · 428 阅读 · 0 评论 -
从数组中寻找和的相加数
从数组中寻找和的相加数Two SumGiven 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, and you may原创 2017-06-20 00:47:25 · 532 阅读 · 0 评论 -
反转整数
反转整数Reverse Integerexample 1input: x = 123, return 321example 2input: x = -123, return -321note: * The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed原创 2017-06-20 01:24:14 · 287 阅读 · 0 评论 -
容器最大盛水量
容器最大盛水量Container With Most WaterGiven 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原创 2017-06-22 21:42:06 · 718 阅读 · 0 评论 -
阿拉伯数字转换成罗马数字
阿拉伯数字转换成罗马数字Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.example 1input: CCCLXXXIXoutput: 389思路用表记录关键的罗马数字和阿拉伯数字,将输入循环除原创 2017-06-23 12:14:37 · 657 阅读 · 0 评论 -
两数相除——不允许使用高级运算
两数相除——不允许使用高级运算Divide Two Integers实现两整数相除,不允许使用乘法、除法、和取余运算。如果结果溢出(int范围为-2147483648 ~ 2147483647),返回MAX_INT题目原文:Divide two integers without using multiplication, division and mod operator.If it is原创 2017-08-07 11:29:21 · 401 阅读 · 0 评论