![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
Johnkui
专注移动应用安全、移动媒体开发和炫酷叼炸天的用户体验设计
展开
-
[LeetCode]31. Next Permutation
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原创 2016-04-13 01:05:44 · 424 阅读 · 0 评论 -
[LeetCode]89. Gray Code
89. Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print t原创 2016-04-17 00:57:55 · 490 阅读 · 0 评论 -
[LeetCode]73. Set Matrix Zeroes
73. Set Matrix Zeroes Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space i原创 2016-04-17 09:59:27 · 569 阅读 · 0 评论 -
[LeetCode]134. Gas Station
134. Gas Station here are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel fro原创 2016-04-17 10:33:58 · 445 阅读 · 0 评论 -
[LeetCode]135. Candy
135. Candy There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have原创 2016-04-17 11:15:16 · 377 阅读 · 0 评论 -
[LeetCode]136. Single Number
136. Single Number Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it原创 2016-04-17 11:28:38 · 472 阅读 · 0 评论 -
[LeetCode]137. Single Number II
137. Single Number II Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you impl原创 2016-04-17 12:09:16 · 450 阅读 · 0 评论 -
[LeetCode]2. Add Two Numbers
2. 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原创 2016-04-17 13:23:53 · 395 阅读 · 0 评论 -
[LeetCode]206. Reverse Linked List
206. Reverse Linked List Reverse a singly linked list. A linked list can be reversed either iteratively or recursively. Could you implement both?分析翻转链表可以通过迭代方式也可以通过递归方式。递归方式主要是确定递归退出条件,当head为空时返回空,当原创 2016-04-17 14:10:44 · 424 阅读 · 0 评论 -
[LeetCode] 92. Reverse Linked List II
92. Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given原创 2016-04-17 16:14:49 · 532 阅读 · 0 评论 -
[LeetCode]86. Partition List
86. Partition List Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of原创 2016-04-17 17:09:31 · 359 阅读 · 0 评论 -
[LeetCode]83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return原创 2016-04-17 17:30:34 · 425 阅读 · 0 评论 -
[LeetCode]80. Remove Duplicates from Sorted Array II
80. Remove Duplicates from Sorted Array II Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given sorted array nums = [1,1,1,2,2,3],Your functio原创 2016-04-17 17:36:50 · 404 阅读 · 0 评论 -
[LeetCode]82. Remove Duplicates from Sorted List II
82. Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3原创 2016-04-17 20:26:40 · 412 阅读 · 0 评论 -
[LeetCode]61. Rotate List
61. Rotate List Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.分析链表旋转问题,不像数组容易知道数组长度,链表只原创 2016-04-17 21:22:36 · 424 阅读 · 0 评论 -
[LeetCode]70. Climbing Stairs
70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?分析题目要求给出爬到原创 2016-04-16 23:29:47 · 347 阅读 · 0 评论 -
[LeetCode]66. Plus One
66. Plus One Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list.分析一个非负整数的原创 2016-04-16 23:00:03 · 433 阅读 · 0 评论 -
[LeetCode]48. Rotate Image
48. Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place?分析题目要求将一个n x n 的二维矩阵进行顺时针90度旋转,直接思原创 2016-04-16 22:41:02 · 365 阅读 · 0 评论 -
[LeetCode]27. Remove Element
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原创 2016-04-13 01:16:47 · 530 阅读 · 0 评论 -
[LeetCode]282. Expression Add Operators
282. Expression Add Operators Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evalu原创 2016-04-13 01:29:08 · 691 阅读 · 0 评论 -
[LeetCode]33. Search in Rotated Sorted Array
Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search.原创 2016-04-10 20:00:21 · 382 阅读 · 0 评论 -
[LeetCode]81. Search in Rotated Sorted Array II
81. Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function原创 2016-04-10 21:43:16 · 457 阅读 · 0 评论 -
[LeetCode]259. 3Sum Smaller
259. 3Sum Smaller Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.原创 2016-04-10 01:45:28 · 1123 阅读 · 0 评论 -
[LeetCode]15. 3Sum
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.原创 2016-04-09 22:33:14 · 406 阅读 · 0 评论 -
[LeetCode]1. Two Sum
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.Example:Given nums原创 2016-04-09 23:15:50 · 486 阅读 · 0 评论 -
[LeetCode]16. 3Sum Closest
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原创 2016-04-10 22:04:57 · 397 阅读 · 0 评论 -
[LeetCode]4. Median of Two Sorted Arrays
4. Median of Two Sorted Arrays There 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 (m+n原创 2016-04-10 22:35:20 · 332 阅读 · 0 评论 -
[LeetCode]128. Longest Consecutive Sequence
128. Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive原创 2016-04-10 22:51:05 · 298 阅读 · 0 评论 -
[LeetCode]60. Permutation Sequence
60. Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123"原创 2016-04-15 00:21:30 · 506 阅读 · 0 评论 -
[LeetCode]36. Valid Sudoku
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 ‘.’. Note:原创 2016-04-15 09:24:06 · 345 阅读 · 0 评论 -
[LeetCode]42. Trapping Rain Water
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原创 2016-04-16 19:53:12 · 536 阅读 · 0 评论 -
[LeetCode]189. Rotate Array
189. Rotate Array Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].分析题目需要旋转一个数组,使得右边的k个元素不变序的搬到数组头部。原创 2016-04-16 21:30:40 · 534 阅读 · 0 评论 -
[LeetCode]19. Remove Nth Node From End of List
19. 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 seco原创 2016-04-17 22:28:59 · 521 阅读 · 0 评论