- 博客(27)
- 收藏
- 关注
原创 Rotate Array -- leetcode
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].Note:Try to come up as many solutions as yo
2015-06-30 16:17:24 411
原创 Largest Number -- leetcode
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2015-06-28 10:35:00 481
原创 Dungeon Game -- latched
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p
2015-06-28 08:55:41 504
原创 Binary Search Tree Iterator -- leetcode
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()
2015-06-26 16:22:10 480
原创 Factorial Trailing Zeroes -- leetcode
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.基本思路:统计n!尾数0的个数。尾数0则是由因子2,5 乘积得来的。要统计0的个数,则需要统计2,5的因子个数。 由于2
2015-06-25 15:50:05 417
原创 Excel Sheet Column Number -- leetcode
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z
2015-06-24 19:41:09 465
原创 Excel Sheet Column Title -- leetcode
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 基本思
2015-06-23 19:02:18 411
原创 Fraction to Recurring Decimal -- leetcode
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.
2015-06-22 12:54:46 418
原创 Compare Version Numbers -- leetcode
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2015-06-22 10:58:16 456
原创 Maximum Gap -- leetcode
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements
2015-06-21 12:22:04 549
原创 Find Peak Element -- leetcode
A 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 multiple peaks, i
2015-06-21 09:02:56 885 1
原创 Intersection of Two Linked Lists -- leetcode
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2015-06-20 09:35:30 524
原创 Min Stack -- leetcode
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get
2015-06-18 19:22:40 370
原创 Maximum Product Subarray -- leetcode
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
2015-06-14 11:53:04 457
原创 Reverse Words in a String -- leetcode
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in
2015-06-10 07:43:11 550
原创 Max Points on a Line -- leetcode
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.基本思路:本题是求解,在同一条直线上点的个数。最大值。2点,能确定一条直线。 而判断第三点,是否位于该值线上。需要用到斜率。即选定一个点,为基准点。 其他点,都对该点求斜
2015-06-08 19:26:08 454
原创 Sort List -- leetcode
Sort a linked list in O(n log n) time using constant space complexity.算法一 自顶向下折半归并,递归使用递归。进行折半。先使用快慢指针,找到中间结点。将链表一分为二。对此两链表进行递归排序后,进行归并。在leetcode上实际执行时间为62ms。/** * Definition for
2015-06-07 20:21:00 395
原创 Insertion Sort List -- leetcode
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
2015-06-07 16:05:45 540
原创 LRU Cache -- leetcode
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if
2015-06-07 09:54:11 471
原创 Binary Tree Postorder Traversal -- leetcode
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut
2015-06-06 11:27:19 398
原创 Binary Tree Preorder Traversal -- leetcode
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti
2015-06-05 07:13:42 607
原创 Reorder List -- leetcode
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}, reorder it to
2015-06-04 08:21:06 570
原创 Linked List Cycle II -- leetcode
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?基本思路:1. 使用快慢指针,进行判断是否存在环。 如果存在,返回快慢指针相遇点
2015-06-02 19:23:14 341
原创 Linked List Cycle -- leetcode
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?基本思路:快慢两指针。一个指针每次移动一步,另一个指针每次移动两步。如存在环,必有相遇的时候。/** * Definition for singly-li
2015-06-02 16:47:06 460
原创 Word Break II -- leetcode
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "
2015-06-02 14:15:20 657
原创 Word Break -- leetcode
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"
2015-06-01 19:12:29 492
原创 Copy List with Random Pointer -- leetcode
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.基本思路:三趟扫描。第一趟,复制节点。并将复制的节点
2015-06-01 11:20:15 471
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人