![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode解题报告
YatKam
成长在于积累,分享是种美德!
展开
-
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.原题链接地址:https://leetcode.com/problems/integer-to-roman/ 分析:题意将阿拉伯数字num转罗马数字 拼写原创 2015-08-13 19:39:20 · 897 阅读 · 0 评论 -
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 as原创 2015-10-17 23:48:15 · 849 阅读 · 0 评论 -
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 plac原创 2015-10-18 10:10:06 · 589 阅读 · 0 评论 -
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原创 2015-10-18 10:44:19 · 972 阅读 · 0 评论 -
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 input cases.N原创 2015-06-05 05:28:49 · 766 阅读 · 0 评论 -
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. 题目来源:https://leetcode.com原创 2015-05-17 16:15:36 · 783 阅读 · 0 评论 -
LeetCode解题报告---Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原题出处:https://leetcode.com/problems/reverse-integer/解题思路:如果输入”100”,”10000”,反转之后输出时应考虑前导‘0’;输入溢出时时以及反转输出时溢出直接原创 2015-06-03 03:55:18 · 640 阅读 · 0 评论 -
LeetCode解题报告--ZigZag Conversion
题目来源:https://leetcode.com/problems/zigzag-conversion/P AH N AP LS I I G YI R 解法一: 间距为: icount = 2 * (nRows - 1) 每列的字符个数为:i = nRows[from 0 to (nRows - 1)] 中间未加粗字符其下标为: mid = j + icount - 2 * i原创 2015-06-02 00:04:47 · 704 阅读 · 0 评论 -
LeetCode解题报告--Remove Nth Node From End of List
**题目:**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 removin原创 2015-09-25 09:58:55 · 737 阅读 · 0 评论 -
LeetCode解题报告--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 pos原创 2015-12-03 20:54:30 · 1834 阅读 · 1 评论 -
LeetCode解题报告-- 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原创 2015-12-03 15:05:12 · 2613 阅读 · 1 评论 -
LeetCode解题报告--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 a原创 2015-12-04 16:58:11 · 1797 阅读 · 0 评论 -
LeetCode解题报告--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 f原创 2015-12-04 13:32:03 · 2407 阅读 · 0 评论 -
LeetCode解题报告--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 comb原创 2015-12-07 21:10:15 · 1171 阅读 · 0 评论 -
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原创 2015-10-17 11:11:31 · 1547 阅读 · 2 评论 -
LeetCode解题报告--Valid Parentheses
**题目:**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, “()原创 2015-09-25 10:23:26 · 611 阅读 · 0 评论 -
Reverse Integer 解题报告
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321原题出处:https://leetcode.com/problems/reverse-integer/解题思路:如果输入”100”,”10000”,反转之后输出时应考虑前导‘0’;输入溢出时时以及反转输出时溢出直接原创 2015-06-03 01:31:45 · 692 阅读 · 0 评论 -
LeetCode解题报告--Palindrome Number
题目:回文数字的判断 Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to strin原创 2015-08-13 17:28:51 · 1492 阅读 · 0 评论 -
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 (i, 0). Fi原创 2015-08-13 17:37:37 · 793 阅读 · 0 评论 -
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. 分析:题意:将给定的罗马数字转为阿拉伯数字 从前往后遍历罗马数字,如果某个数比前一个数小,则把该数加入到结果中; 反之,则在结果中两次减去前一个数并加原创 2015-08-13 19:46:54 · 964 阅读 · 0 评论 -
LeetCode解题报告--Longest Common Prefix
题目:最长公共前缀 Write a function to find the longest common prefix string amongst an array of strings.分析:题意找出所有字符串的最长公共前缀。 思路简单:如下步骤 1. 找出字符串数组中字符串长度最小的字符串minStr 2. minStr与其余的字符串逐个字符比较,确定最长公共前缀java 代码:(a原创 2015-08-14 15:43:40 · 1544 阅读 · 0 评论 -
LeetCode解题报告--3 Sum
题目: 3 个数和问题 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原创 2015-08-16 16:37:27 · 1499 阅读 · 1 评论 -
LeetCode解题报告--3Sum Closest
题目:与3数和最接近的和 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原创 2015-08-16 16:46:24 · 1010 阅读 · 0 评论 -
LeetCode解题报告--4Sum
题目: 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原创 2015-08-17 17:54:37 · 889 阅读 · 0 评论 -
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:D原创 2015-08-17 17:43:42 · 2454 阅读 · 0 评论 -
LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结
前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题,该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sort()可实现,而本文则着重探讨关于KSum问题。 leetcode求和问题描述(K sum problem): K sum的求和问题一般是这样子描述的:给你一组N个数字(比如 vector原创 2015-08-17 18:22:02 · 3676 阅读 · 0 评论 -
LeetCode解题报告--Merge Two Sorted Lists
**题目:**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.分析:题意要求将两个排好序List链表整合原创 2015-09-25 10:53:15 · 933 阅读 · 0 评论 -
LeetCode解题报告--Merge k Sorted Lists
**题目:**Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析:题意要求将k个排好序的链表,整合为一个排好序链表,该题是之前的合并两个排好序的链表的延伸,延伸为一般情况。基本思想与两链表合并一样,原创 2015-09-26 12:37:43 · 809 阅读 · 0 评论 -
LeetCode解题报告--Generate Parentheses
**题目:**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-09-25 13:56:08 · 682 阅读 · 0 评论 -
LeetCode解题报告--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 n原创 2015-12-07 20:24:31 · 1064 阅读 · 1 评论