leetcode
文章平均质量分 94
Icoding_F2014
相信代码可以变化世界
展开
-
leetcode 649. Dota2 Senate
这是一道博弈论的题目。题目是说,有来自两个不同队伍R和D的一队人在玩游戏。每个回合,从左往右,这些人可以有两个权利:在把任意一个对手投死统计当前队伍里面是不是都是来自同一个队伍,如果是的话,就可以宣布这个个队伍获胜了。已经死掉的人不能在投别人了。例如:队伍是:RD第一回合,那么R1R_1R1 可以把D2D_2D2投死,于是D2D_2D2 就没法投票了。第二回合,队伍只剩下...原创 2019-12-22 17:55:18 · 220 阅读 · 0 评论 -
leetcode: 连续子串和/积的相关题目汇总及总结
560. Subarray Sum Equals K题目Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Ou...原创 2019-12-08 20:50:41 · 411 阅读 · 0 评论 -
287. Find the Duplicate Number 寻找重复元素
题目Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,...原创 2019-10-25 20:08:49 · 207 阅读 · 0 评论 -
Leetcode : 162 /852 /1095 寻找局部最大/最小值
题目:A peak element is an element that is greater than its neighbors.Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index.The array may contain multiple peak...原创 2019-10-22 00:02:01 · 1830 阅读 · 0 评论 -
leetcode.105 & 106 基于(前序/后序)和中序 遍历结果 重建二叉树
105 和 106 涉及通过中序遍历结果,配合前序或后序遍历结果来重建原来的二叉树。问题不难,在学习树的遍历的时候,其实应该学会如何解决这种问题。这类问题的核心思路在于:基于前序,推断出根节点。这是因为前序遍历的过程是,先访问根节点,再访问左子树,最后访问右子树。而后序遍历的过程是先访问左子树,再访问右子树,最后访问根。找到根节点后,再通过中序遍历的结果,找到根在中序遍历中的位置 iii。...原创 2019-10-13 08:37:49 · 125 阅读 · 0 评论 -
189. Rotate Array
Given an array, rotate the array to the right by k steps, where k is non-negative.Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,...原创 2019-09-11 20:23:03 · 138 阅读 · 0 评论 -
54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.Example 1:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5]Exa...原创 2019-09-08 23:10:40 · 105 阅读 · 0 评论 -
2019-08-08-02 Add Two Numbers
You 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 two numbers and return i...原创 2019-08-08 23:26:11 · 123 阅读 · 0 评论 -
5. 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.Example 1:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.Example ...原创 2019-08-25 13:29:15 · 125 阅读 · 0 评论 -
6. 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 I G...原创 2019-08-26 16:29:44 · 169 阅读 · 0 评论 -
8. String to Integer (atoi)
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus si...原创 2019-08-27 08:22:12 · 82 阅读 · 0 评论 -
12. Integer to Roman
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D ...原创 2019-08-28 20:01:24 · 85 阅读 · 0 评论 -
16. 3Sum Closest
Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...原创 2019-08-31 16:57:38 · 97 阅读 · 0 评论 -
18. 4Sum
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of tar...原创 2019-08-31 18:32:53 · 88 阅读 · 0 评论 -
1. Two Sum
Given 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 not use the same e...原创 2019-08-31 21:00:50 · 74 阅读 · 0 评论 -
XSUM-从数组中X个元素,使得它们的和为target的问题总结
XSUM问题:即从数组中找出X个元素,使得这些元素的和为某个给定的target,每个元素只能使用一次。其中 x≥2x\geq 2x≥2这类问题的通用解法如下:将数组 numsnumsnums 排序,排序的目的 一方面利于去重,另外一方面利于遍历,设数组长度为 nnn。写一个X-2 重的循环,每一层循环表示 这前X-2个数字的遍历过程,而且内层循环的循环变量 indexjindex_{j}i...原创 2019-09-01 07:29:30 · 642 阅读 · 0 评论 -
leetcode:19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the l...原创 2019-09-02 07:35:14 · 173 阅读 · 0 评论 -
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[1->4->5,1->3->4,2->6]Output: 1->1->2->3->4->4->...原创 2019-09-03 08:25:04 · 95 阅读 · 0 评论 -
Leetcode 排列相关的题目
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 or...原创 2019-09-05 08:44:37 · 197 阅读 · 0 评论 -
48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix dire...原创 2019-09-07 21:04:20 · 140 阅读 · 0 评论 -
LeetCode刷题指南(持续更新)
【128】最长数值连续递增子序列题目:https://leetcode.com/problems/longest-consecutive-sequence/description/解题方法:带路径压缩以及带元素统计的并查集https://blog.csdn.net/jmh1996/article/details/84198246 (应用部分)【200】小岛个数题目:https://l...原创 2018-11-18 15:45:16 · 1561 阅读 · 0 评论