LeetCode
一只奋斗的小菜鸟
迷茫,本就是青春该有的样子 ,但不要让未来的你,讨厌现在的自己。
展开
-
LeetCode-----First Unique Character in a String
我将于茫茫人海中访我唯一灵魂之伴侣;得之,我幸;不得,我命 。 一徐志摩要求:给定一个字符串,找到第一个不重复的字符,并返回它的索引。如果不存在,返回-1。 举例:s = "leetcode",return 0。s = "loveleetcode",return 2 。public class FirstUniqueCharacter { public stat原创 2017-09-15 14:14:22 · 287 阅读 · 0 评论 -
LeetCode----- 167.Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number原创 2017-09-21 20:31:00 · 313 阅读 · 0 评论 -
LeetCode----- 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 by modifying the input array in-原创 2017-11-09 20:38:15 · 145 阅读 · 0 评论 -
LeetCode----- 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 second node from the end, the原创 2017-10-14 20:42:27 · 176 阅读 · 0 评论 -
LeetCode----- 2.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原创 2017-10-16 08:32:00 · 231 阅读 · 0 评论 -
LeetCode----- 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 1->2->3.给定已排序好的链表,删除链表中所有的重复项,使原创 2017-10-24 19:48:15 · 166 阅读 · 0 评论 -
Leetcode----- 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->4->4->5, return 1->2->5.Given 1->1-原创 2017-10-24 21:44:29 · 330 阅读 · 0 评论 -
LeetCode----- 21.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.合并两个已经排序的链表,并将其作为一个新链表返回。新的链表应该通过拼接前两个链表的节点来完成。代码如下:原创 2017-10-16 20:24:32 · 193 阅读 · 0 评论 -
LeetCode----- 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 as the lowest possib原创 2017-11-14 19:35:13 · 234 阅读 · 0 评论 -
LeetCode----- 34.Search for a Range
Given 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(log n).If the原创 2018-01-02 20:32:48 · 190 阅读 · 0 评论 -
LeetCode----- 35.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 array.原创 2018-01-03 19:49:51 · 176 阅读 · 0 评论 -
LeetCode----- 39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) 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原创 2018-01-05 21:54:20 · 281 阅读 · 0 评论 -
LeetCode----- 40.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 combina原创 2018-01-08 20:55:16 · 174 阅读 · 0 评论 -
LeetCode----- 1.TwoSum
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 sam原创 2017-09-20 08:37:54 · 374 阅读 · 0 评论 -
LeetCode----- 7.Reverse Integer
Example1: x = 123,return 321 Example2: x = -123,return -321Note:The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.原创 2017-09-22 20:43:35 · 347 阅读 · 0 评论 -
LeetCode----- 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 the possible input ca原创 2017-09-25 15:51:00 · 313 阅读 · 0 评论 -
LeetCode----- 24.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 space. Y原创 2017-10-17 20:03:36 · 212 阅读 · 0 评论 -
LeetCode----- 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 the nodes in each of原创 2017-10-27 09:07:11 · 211 阅读 · 0 评论 -
LeetCode----- 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.给定一个单链表,将单链表旋转到右边的k个位置,k为非负数。原创 2017-10-20 21:31:17 · 202 阅读 · 0 评论 -
LeetCode----- 26. 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 by modifyin原创 2017-11-08 20:34:30 · 141 阅读 · 0 评论 -
LeetCode----- 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 would have exact原创 2017-10-13 19:35:42 · 183 阅读 · 0 评论 -
LeetCode----- 18.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: The solution原创 2017-10-12 08:54:13 · 730 阅读 · 0 评论 -
LeetCode----- 15.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.Note: The solution set must not c原创 2017-10-11 11:35:15 · 159 阅读 · 0 评论 -
LeetCode----- 20.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, "()" and "()[]{}" are all valid原创 2017-09-30 09:59:47 · 256 阅读 · 0 评论 -
LeetCode----- 14.Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.解题思路:首先从字符串数组中获取长度最小的字符串,然后循环遍历字符串数组,判断数组中的当前的字符串第一次出现最小字符串的位置,如果没有,则缩小最小字符串,如果最小字符串长度=0,则返回为“”。public static原创 2017-09-28 22:01:42 · 214 阅读 · 0 评论 -
LeetCode----- 13.Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.罗马记数方法:基本字符IVXLCDM原创 2017-09-27 20:39:47 · 219 阅读 · 0 评论 -
LeetCode----- 12.Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.解题思路:直接对输入的num,直接求出各位上的数。public static String intToRoman(int num) { Map map = new原创 2017-10-13 21:07:17 · 220 阅读 · 0 评论 -
LeetCode----- 9.Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.本题获取知识点:什么是回文数。概念:设n是一任意自然数,若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。 例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数。代码如下:publ原创 2017-09-25 19:35:14 · 322 阅读 · 0 评论 -
LeetCode ----- 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 matr原创 2018-01-10 19:38:11 · 206 阅读 · 0 评论