Java初刷LeetCode
文章平均质量分 68
大三狗一枚,马上面临这实习,才发现自己的代码水平渣的一比,
而且数据结构的知识基本考完试就忘了差不多了。
相信大多数大三狗都有这感觉。
So,跟我一起刷LeetCode,提升自己的能力。
争取每日一道,7月前刷完~
一起Fighting。
大三狗
这个作者很懒,什么都没留下…
展开
-
LeetCode 28 Implement strStr() 找到字串返回位置。
题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.翻译:找到字符串的子串位置,并返回。如果没有则返回-1思路:通过最简单的BF遍历,如果不符合则指向下一个字符,原创 2015-05-07 16:54:38 · 1447 阅读 · 1 评论 -
LeetCode 27 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 len原创 2015-05-07 12:39:27 · 1725 阅读 · 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 in p原创 2015-05-07 12:26:40 · 1671 阅读 · 1 评论 -
LeetCode 25 Reverse Nodes in k-Group K个一组反转节点
题目: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原创 2015-05-06 15:02:57 · 2357 阅读 · 0 评论 -
LeetCode24 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 s原创 2015-05-06 13:55:14 · 2546 阅读 · 3 评论 -
LeetCode23 Merge k Sorted Lists 把K个有序链表连接成一个
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.翻译:把K个有序的链表合成一个,返回。思路:这道题和昨天的Merge 2 Lists有些类似。但是k不确定,如果用每个都去遍历的话,肯定是不会通过的。So、可以想到的是归原创 2015-05-06 11:17:26 · 2513 阅读 · 0 评论 -
LeetCode22 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-05-05 13:24:39 · 2787 阅读 · 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.翻译:把2个有序链表连接,返回一个新链表思路:很简单,就是遍历每个节点,小的话添加在原创 2015-05-05 10:21:26 · 2387 阅读 · 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原创 2015-05-05 10:12:34 · 2600 阅读 · 0 评论 -
LeetCode 19 Remove Nth Node From End of List 移除倒数第N个节点
题目: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原创 2015-05-04 15:37:00 · 2603 阅读 · 1 评论 -
LeetCode 18 4sum 找出4个数,使得他们的和等于target
题目: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:原创 2015-05-04 15:05:40 · 2554 阅读 · 0 评论 -
LeetCode 17 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原创 2015-05-04 10:38:46 · 3176 阅读 · 0 评论 -
LeetCode 16 3Sum Closest 找出最接近指定target的三个数的和
题目: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 hav原创 2015-05-04 09:26:28 · 2308 阅读 · 0 评论 -
LeetCode 15 3Sum 找出数组里面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 tripl原创 2015-04-23 13:17:25 · 4068 阅读 · 0 评论 -
LeetCode13 Roman to Integer 罗马转为数字
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.翻译:把罗马转为数字思路:如果是单纯的一个罗马字母比较好处理,但是对于4,9这样的,应该看它下一个字符代表的数字是不是比他大,要是大的话减去当前的字符原创 2015-04-22 13:55:31 · 1993 阅读 · 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.翻译:给一个整数,把他转换为罗马数字输出。这道题是简单的字符转换的问题。只要了解罗马数字代表的含义即可。罗马数字里面只有 1,5,10原创 2015-04-22 12:56:24 · 1728 阅读 · 0 评论 -
LeetCode 11 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,原创 2015-04-22 11:11:28 · 2268 阅读 · 0 评论 -
LeetCode 10 Regular Expression Matching 正则匹配
题目:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire原创 2015-04-21 19:08:32 · 3122 阅读 · 0 评论 -
LeetCode 9 Palindrome Number 回文数字
题目:Determine whether an integer is a palindrome. Do this without extra space.翻译:判断一个数字是否是回文数,不要额外空间。解题思路:因为数字既然传过去了,就不会有越界的问题。每次只需要取最前面和最后面的那一位数字进行比较,相同则继续,不同则返回、首先要获取数字的位数,假设数字是12344321,一共有8位。原创 2015-04-20 14:55:27 · 3334 阅读 · 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 i原创 2015-04-20 12:55:57 · 3090 阅读 · 0 评论 -
Leetcode 7 Reverse Integer 反转数字
题目:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321翻译就是把一个数字反过来输出。解题思路:这道题目看起来比较简单。无非就是一个数字取个位,作为另一个高位。无非是在10的运算。代码1: public static int rever原创 2015-04-20 10:28:58 · 6012 阅读 · 0 评论 -
leetcode 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原创 2015-04-17 13:18:20 · 3267 阅读 · 0 评论 -
LeetCode 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, and there exists one unique longest palindromic substring.翻译:求字符串的最长回文子串原创 2015-04-17 10:37:27 · 3842 阅读 · 0 评论 -
leetcode 4 Median of Two Sorted Arrays
题目:There are two sorted arrays A and B 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)).看到题目,首先想到的是 把2个数组合并成一个,然后在去中间位原创 2015-04-16 13:52:53 · 3419 阅读 · 0 评论 -
LeetCode 3 Longest substring without Repeating A
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is原创 2015-04-15 17:06:02 · 2804 阅读 · 0 评论 -
LeetCode 开刷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原创 2015-04-15 14:00:40 · 3303 阅读 · 0 评论 -
LeetCode开刷,1.Two Sum Java
大学学了一堆理论,编码水平渣。果然应该刷刷题了。正好最近看java ,试着就java写一写。水平略渣。。题目:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum shou原创 2015-04-15 13:20:46 · 4290 阅读 · 0 评论