
leetcode
文章平均质量分 56
ayst123
这个作者很懒,什么都没留下…
展开
-
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 return it as a link原创 2014-09-04 09:56:57 · 420 阅读 · 0 评论 -
Swap Nodes in Pairs
自己做出来了,题目比较简单原创 2014-09-05 10:27:17 · 344 阅读 · 0 评论 -
Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?原创 2014-08-23 08:23:13 · 403 阅读 · 0 评论 -
Remove Duplicates from Sorted List
算是第一次一次AC的题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.分析:1原创 2014-08-23 08:48:16 · 382 阅读 · 0 评论 -
Linked List Cycle
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # @param head, a ListNode # @return a boo原创 2014-08-23 06:35:00 · 622 阅读 · 0 评论 -
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.原创 2014-08-24 10:41:04 · 366 阅读 · 0 评论 -
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.分析:原创 2014-08-23 22:51:04 · 432 阅读 · 0 评论 -
Partition List
自己做出来的,还可以f原创 2014-08-24 12:17:46 · 415 阅读 · 0 评论 -
Remove Nth Node From End of List
自己原来想到了双指针法,后来看了下网上的解答,证明是对的。原创 2014-08-24 11:09:40 · 444 阅读 · 0 评论 -
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,Giv原创 2014-08-23 12:09:36 · 411 阅读 · 0 评论 -
Merge Sorted Array
这题开始的思路时错的,后来看了原创 2014-08-25 07:39:21 · 469 阅读 · 0 评论 -
Reverse Linked List II
看了网上才想到分析: 刚开始想原创 2014-08-26 06:05:07 · 416 阅读 · 0 评论 -
Merge k Sorted Lists
看了网上的讲解一开始想一个一个去合并,复杂度是fa原创 2014-08-26 07:17:09 · 463 阅读 · 0 评论 -
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 length.原创 2014-11-08 00:47:23 · 353 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
自己搞定Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now原创 2014-11-08 12:52:56 · 471 阅读 · 0 评论 -
Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha原创 2014-11-08 13:40:45 · 477 阅读 · 0 评论 -
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 place with原创 2014-11-08 01:56:45 · 333 阅读 · 0 评论 -
Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the largest原创 2014-11-08 14:13:37 · 385 阅读 · 0 评论 -
Triangle
ZIJGiven a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4原创 2014-11-08 15:29:12 · 382 阅读 · 0 评论 -
Reorder List
参考了网上答案Given 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}, r原创 2014-11-02 12:08:18 · 364 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity.用归并算法,先找到原创 2014-11-03 01:07:05 · 422 阅读 · 0 评论 -
Reverse Nodes in k-Group
自己做chu lGiven a linked list, reverse the nodes of a linked list kat 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 rema原创 2014-11-03 04:00:14 · 477 阅读 · 0 评论 -
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?分析: 题目比较简单,小的西晋原创 2014-11-04 03:01:23 · 417 阅读 · 0 评论 -
Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the原创 2014-11-04 04:20:55 · 440 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2014-11-04 03:27:04 · 390 阅读 · 0 评论 -
Unique Paths
A robot is located at the top-left corner of a m x ngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the b原创 2014-11-04 03:50:31 · 390 阅读 · 0 评论 -
Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].easy to solveclass Solution: # @return a list of integers def getRow原创 2015-01-08 12:50:46 · 338 阅读 · 0 评论 -
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.not hardrecursio原创 2015-01-09 11:07:36 · 492 阅读 · 0 评论 -
Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5It's easy to solve.class Solution: # @return a list of lists of integers def generate(sel原创 2015-01-08 12:49:25 · 381 阅读 · 0 评论 -
Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli原创 2015-01-08 13:10:55 · 345 阅读 · 0 评论 -
Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2015-01-08 12:51:39 · 439 阅读 · 0 评论 -
Leetcode: Tenth Line
QuestionHow would you print just the 10th line of a file?For example, assume that file.txt has the following content:Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 You原创 2015-05-10 10:06:21 · 1105 阅读 · 0 评论 -
Leetcode: Valid Phone Numbers
QuestionGiven a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers.You may assume that a valid phone number must appea原创 2015-05-10 11:28:07 · 1352 阅读 · 0 评论 -
Leetcode: Word Frequency
QuestionWrite a bash script to calculate the frequency of each word in a text file words.txt.For simplicity sake, you may assume:words.txt contains only lowercase characters and space ’ ’ characters.原创 2015-05-10 21:50:27 · 813 阅读 · 0 评论 -
Leetcode: Transpose File
QuestionGiven a text file file.txt, transpose its content.You may assume that each row has the same number of columns and each field is separated by the ’ ’ character.For example, if file.txt has the f原创 2015-05-10 21:26:25 · 1185 阅读 · 0 评论 -
Leetcode: Word Search
Get idea from Code Ganker′s (优快云) solution, also from this solutionQuestionGiven a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially ad原创 2015-05-11 10:12:46 · 400 阅读 · 0 评论 -
Leetcode: Search in Rotated Sorted Array
Get idea from Code Ganker′s (优快云) Solution, and Leetcote articleQuestionSuppose 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 a原创 2015-05-11 11:02:10 · 501 阅读 · 0 评论 -
Leetcode: Sort Colors
QuestionGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the intege原创 2015-05-12 15:34:45 · 353 阅读 · 0 评论 -
Leetcode: Search in Rotated Sorted Array II
Get idea from Code Ganker (优快云)′solutionQuestionFollow 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原创 2015-05-12 06:32:00 · 393 阅读 · 0 评论 -
Leetcode: Search for a Range
Get idea from hereQuestionGiven a sorted array of integers, 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 tar原创 2015-05-12 11:03:09 · 327 阅读 · 0 评论