Algorithm
文章平均质量分 55
hale1007
ZJUCS小硕一枚,进阶中的菜鸟
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
[LeetCode] Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2014-05-03 15:02:42 · 421 阅读 · 0 评论 -
[LeetCode] Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on原创 2014-10-16 01:14:27 · 460 阅读 · 0 评论 -
[LeetCode] Longest Substring Without Repeating Characters
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 3. Fo原创 2014-10-16 16:53:04 · 483 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may原创 2014-05-01 10:39:50 · 489 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2014-05-01 20:31:08 · 400 阅读 · 0 评论 -
[LeetCode] Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3,原创 2014-05-03 23:03:55 · 483 阅读 · 0 评论 -
[LeetCode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is def原创 2014-05-09 17:10:25 · 570 阅读 · 0 评论 -
[LeetCode] Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2014-04-30 19:21:19 · 485 阅读 · 0 评论 -
[LeetCode] Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.原创 2014-05-13 11:54:32 · 1014 阅读 · 0 评论 -
[LeetCode] Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.原创 2014-05-01 19:00:43 · 451 阅读 · 0 评论 -
[LeetCode] Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.原创 2014-05-02 01:45:52 · 385 阅读 · 0 评论 -
[LeetCode] Insertion Sort List
Sort a linked list using insertion sort.原创 2014-10-15 22:46:22 · 505 阅读 · 0 评论 -
[LeetCode] Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-04-30 22:24:15 · 493 阅读 · 0 评论 -
求二叉树中节点的最大距离
昨天面试问道这个问题,这个问题在编程之美上见过,但是不记得过程了。没答上来。jin原创 2014-11-03 11:35:51 · 560 阅读 · 0 评论 -
[LeetCode] Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?原创 2014-05-01 14:42:49 · 408 阅读 · 0 评论 -
[LeetCode] Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-05-03 15:28:32 · 436 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2014-05-01 10:36:39 · 509 阅读 · 0 评论 -
[LeetCode] Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { int base[] = {原创 2014-05-01 19:19:05 · 414 阅读 · 0 评论 -
[LeetCode] 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:"((()))", "(()())", "(())()", "()(())", "()()()原创 2014-05-09 16:43:20 · 481 阅读 · 0 评论 -
[LeetCode] Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2014-11-01 19:57:35 · 560 阅读 · 0 评论 -
[LeetCode] Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2014-11-01 18:07:08 · 582 阅读 · 0 评论 -
[LeetCode] Permutations
Given a collection of 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], and [3,2,1].class Solution原创 2014-11-01 18:01:57 · 488 阅读 · 0 评论 -
[LeetCode] 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 l原创 2014-05-09 19:32:38 · 441 阅读 · 0 评论 -
[LeetCode] 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.原创 2014-11-07 01:21:09 · 507 阅读 · 0 评论 -
[LeetCode] Linked List Cycle
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-linked list. * struct ListNode { * int val; *原创 2014-03-26 23:35:55 · 554 阅读 · 0 评论 -
[LeetCode] 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].Note:Could you optimize your algorithm to use only O(k) extra space?原创 2014-05-01 11:30:51 · 390 阅读 · 0 评论 -
[LeetCode] 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 L S I原创 2014-05-04 10:10:19 · 486 阅读 · 0 评论 -
[LeetCode] Copy List with Random Pointer
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.原创 2014-04-30 16:55:56 · 443 阅读 · 0 评论 -
[LeetCode] 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原创 2014-10-16 20:53:50 · 396 阅读 · 0 评论 -
[LeetCode] Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tr原创 2014-05-01 21:22:09 · 567 阅读 · 0 评论 -
[LeetCode] Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You原创 2014-05-03 14:35:49 · 444 阅读 · 0 评论 -
[LeetCode] 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 possible o原创 2014-05-03 15:56:27 · 439 阅读 · 0 评论 -
[LeetCode] Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /原创 2014-05-01 20:15:28 · 410 阅读 · 0 评论 -
[LeetCode] Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m原创 2014-11-01 22:27:14 · 503 阅读 · 0 评论 -
[LeetCode] Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order do原创 2014-05-03 17:52:07 · 486 阅读 · 0 评论 -
[LeetCode] Divide Two Integers
Divide two integers without using multiplication, division and mod operator.原创 2014-10-16 22:23:20 · 416 阅读 · 0 评论 -
[LeetCode] 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-10-16 17:29:24 · 429 阅读 · 0 评论 -
[LeetCode] Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2014-05-01 10:38:24 · 524 阅读 · 0 评论 -
[LeetCode] Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2014-05-01 10:57:51 · 373 阅读 · 0 评论 -
[LeetCode] Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t原创 2014-04-30 19:23:09 · 404 阅读 · 0 评论
分享