![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
大大kc
今日事,今日毕
展开
-
leetcode1. Two Sum
1. 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 not use th原创 2017-02-08 22:28:54 · 351 阅读 · 0 评论 -
leetcode9. Palindrome Number
9. Palindrome NumberDetermine whether an integer is a palindrome. Do this without extra space.解法一借助leetcode7方法,将整数逆转,判断是否相等,同时负数和整数溢出时均返回false。public class Solution { public boolean isPalindrome(in原创 2017-02-27 22:40:53 · 326 阅读 · 0 评论 -
leetcode7. Reverse Integer
7. Reverse IntegerReverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers.Note: The input is assumed to be a 32-bit signed integer. Your funct原创 2017-02-27 22:16:14 · 345 阅读 · 0 评论 -
leetcode8. String to Integer (atoi)
8. 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原创 2017-02-28 18:50:14 · 186 阅读 · 0 评论 -
leetcode2. Add Two Numbers
leetcode2.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原创 2017-02-10 13:18:38 · 424 阅读 · 0 评论 -
leetcode11. Container With Most Water
11. Container With Most WaterGivenn 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,原创 2017-03-01 14:37:07 · 188 阅读 · 0 评论 -
leetcode12. Integer to Roman
12. Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解法一将每一位,从0-9相应的罗马数字列出来,相连接。public class Solution { public static String原创 2017-03-01 15:35:30 · 204 阅读 · 0 评论 -
leetcode13. Roman to Integer
13. Roman to IntegerGiven a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.解法将各个罗马字母代表的阿拉伯数字加起来,但是4,9,40,90,400,900比较特殊,需要区别对待。/*String[] M = {"", "M原创 2017-03-01 16:04:00 · 189 阅读 · 0 评论 -
leetcode14. Longest Common Prefix
14. Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.解法一先找出字符数组中最短的数组,然后用最短的字符的每一位检验其他字符与该位是否相等。public class Solution { public String longe原创 2017-03-01 16:32:51 · 201 阅读 · 0 评论 -
leetcode83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted ListGiven 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 1-原创 2017-03-17 22:08:29 · 163 阅读 · 0 评论 -
leetcode82. Remove Duplicates from Sorted List II
82. Remove Duplicates from Sorted List IIGiven 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->4原创 2017-03-17 22:47:47 · 155 阅读 · 0 评论 -
leetcode206. Reverse Linked List
206. Reverse Linked ListReverse a singly linked list.解法在头节点前添加一个结点。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { va原创 2017-03-18 00:13:25 · 182 阅读 · 0 评论 -
leetcode3. Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters原创 2017-02-26 16:26:18 · 361 阅读 · 0 评论 -
leetcode6. ZigZag Conversion
6. ZigZag ConversionThe 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原创 2017-02-26 22:24:35 · 288 阅读 · 0 评论 -
leetcode5. Longest Palindromic Substring
5.Given 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: “aba” is also a valid answer. Example:Inpu原创 2017-02-26 19:06:14 · 349 阅读 · 0 评论 -
leetcode150. Evaluate Reverse Polish Notation
150. Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another express原创 2017-03-02 23:40:40 · 206 阅读 · 0 评论 -
leetcode78. Subsets
78. SubsetsGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,3], a solution is:[ [3], [1],原创 2017-03-05 16:50:57 · 269 阅读 · 0 评论 -
leetcode46. Permutations
46. PermutationsGiven 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],原创 2017-03-05 18:32:36 · 198 阅读 · 0 评论 -
leetcode92. Reverse Linked List II
92. Reverse Linked List IIReverse 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 m,原创 2017-03-18 22:00:39 · 200 阅读 · 0 评论 -
leetcode86. Partition List
86. Partition ListGiven 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 the nod原创 2017-03-18 22:27:34 · 172 阅读 · 0 评论 -
leetcode148. Sort List
148. Sort ListSort a linked list in O(n log n) time using constant space complexity.解法归并排序。用快慢指针法找到中间结点。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListN原创 2017-03-18 23:45:52 · 203 阅读 · 0 评论 -
leetcode143. Reorder List
143. Reorder ListGiven a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’ values.For example, Given {1,2,3,4}, reorde原创 2017-03-19 16:13:38 · 223 阅读 · 0 评论 -
leetcode141. Linked List Cycle
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?解法快慢指针法,当两指针重合,则有环。/** * Definition for singly-linked list. * class原创 2017-03-19 16:42:37 · 204 阅读 · 0 评论 -
leetcode142. Linked List Cycle II
142. Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up: Can you solve it without using ex原创 2017-03-19 17:05:20 · 222 阅读 · 0 评论 -
leetcode496. Next Greater Element I
496. Next Greater Element IYou are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corres原创 2017-03-19 20:10:42 · 322 阅读 · 0 评论 -
leetcode21. Merge Two Sorted Lists
21. Merge Two Sorted ListsMerge 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.解法归并排序。/** * Definition for singl原创 2017-03-19 20:49:03 · 170 阅读 · 0 评论 -
leetcode74. Search a 2D Matrix
74. Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right. The first原创 2017-03-10 13:42:48 · 174 阅读 · 0 评论 -
leetcode35. Search Insert Position
35. Search Insert PositionGiven 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 dup原创 2017-03-10 09:58:54 · 209 阅读 · 0 评论 -
leetcode34. Search for a Range
34. Search for a RangeGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(l原创 2017-03-10 00:22:47 · 173 阅读 · 0 评论 -
leetcode90. Subsets II
90. Subsets IIGiven a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,2],原创 2017-03-09 21:08:03 · 215 阅读 · 0 评论 -
leetcode263. Ugly Number
263. Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not原创 2017-03-07 18:48:02 · 173 阅读 · 0 评论 -
leetcode202. Happy Number
202. Happy NumberWrite an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of原创 2017-03-07 20:58:42 · 143 阅读 · 0 评论 -
leetcode240. Search a 2D Matrix II
240. Search a 2D Matrix IIWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to r原创 2017-03-11 11:40:12 · 254 阅读 · 0 评论 -
leetcode278. First Bad Version
278. First Bad VersionYou are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is d原创 2017-03-11 12:03:45 · 161 阅读 · 0 评论 -
leetcode162. Find Peak Element
162. Find Peak ElementA peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multip原创 2017-03-11 12:36:07 · 160 阅读 · 0 评论 -
leetcode153. Find Minimum in Rotated Sorted Array
153. Find Minimum in Rotated Sorted ArraySuppose an array sorted in ascending order 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).Find the minimum原创 2017-03-11 13:05:21 · 185 阅读 · 0 评论 -
leetcode154. Find Minimum in Rotated Sorted Array II
154. Find Minimum in Rotated Sorted Array IISuppose an array sorted in ascending order 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).Find the minim原创 2017-03-11 13:48:42 · 160 阅读 · 0 评论 -
leetcode33. Search in Rotated Sorted Array
33. Search in Rotated Sorted ArraySuppose an array sorted in ascending order 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 v原创 2017-03-11 17:50:55 · 147 阅读 · 0 评论 -
leetcode81. Search in Rotated Sorted Array II
81. Search in Rotated Sorted Array IISuppose an array sorted in ascending order 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).Write a function to d原创 2017-03-11 18:16:05 · 188 阅读 · 0 评论 -
leetcode344. Reverse String
344. Reverse StringWrite a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.解法数组中前后进行交换。然后new String(char[] array).public class Solution原创 2017-03-11 18:47:19 · 163 阅读 · 0 评论