- 博客(78)
- 资源 (9)
- 收藏
- 关注
原创 Leetcode: 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. /** * Definition for singly-linked list. * struct
2013-09-30 23:46:13 2058
原创 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 ] ]
2013-09-30 23:23:06 2212
原创 Leetcode: 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
2013-09-30 22:27:46 2021
原创 Leetcode: Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before coding.
2013-09-30 11:46:51 10485 3
原创 Leetcode: 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, 0). Fin
2013-09-30 11:19:05 5725
原创 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
2013-09-28 01:43:38 1860
原创 Leetcode: Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. string longestCommonPrefix(vector &strs) { // Start typing your C/C++ solution below // DO NOT
2013-09-28 01:22:51 2672
原创 Leetcode: Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe
2013-09-28 01:03:05 4547 3
原创 Leetcode: Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total nu
2013-09-28 00:43:21 2515
原创 Leetcode: Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function
2013-09-27 22:40:57 1523 1
原创 Leetcode: Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each
2013-09-27 22:39:01 1625
原创 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 N A P L S I
2013-09-27 16:16:14 2161
原创 Leetcode: Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.Th
2013-09-27 12:36:18 1203
原创 Leetcode: Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2013-09-27 11:40:28 1350 1
原创 Leetcode: Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,3,2]. /** * Definition for b
2013-09-27 11:31:03 1026
原创 leetcode_question_57 Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times. E
2013-09-27 00:33:11 1685
原创 leetcodequestion_56 Merge Intervals
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. vector merge(vector& intervals) { // Start t
2013-09-26 23:08:51 1365
原创 leetcode_question_45 Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal i
2013-09-26 11:10:34 1873
原创 leetcode_question_55 Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine i
2013-09-25 13:23:16 1097
原创 leetcode_question_50 Pow(x, n)
Implement pow(x, n). class Solution { public: double pow(double x, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if(n==0)return
2013-09-25 13:07:17 1805
原创 leetcode_question_66 Plus One
Given a number represented as an array of digits, plus one to the number. vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() funct
2013-09-25 12:34:18 1434
原创 leetcode_question_75 Sort Colors
Given 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 integer
2013-09-25 11:57:59 1979
原创 strcpy, strcat, strcmp, strlen,memcpy
微软的几个源码: /*** *char *strcpy(dst, src) - copy one string over another * *Purpose: * Copies the string src into the spot specified by * dest; assumes enough room. * *Entry: * char * dst - string over
2013-09-25 11:28:22 912
原创 leetcode_question_38 Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read
2013-09-24 00:37:00 2755
原创 Problem A. Read Phone Number
Problem Do you know how to read the phone numbers in English? Now let me tell you. For example, In China, the phone numbers are 11 digits, like: 15012233444. Someone divides the numbers into 3-4-4
2013-09-24 00:23:06 1111
原创 leetcode_question_88 Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space to hold additional elements from B. The number of elements initialized in
2013-09-23 16:57:10 1125
原创 leetcode_question_103 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 binar
2013-09-23 16:44:37 1174
原创 leetcode_question_101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f
2013-09-23 00:36:59 3165 3
原创 leetcode_question_109 Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Recurse: /** * Definition for singly-linked list. * struct ListNode { * int
2013-09-23 00:16:32 1906
原创 leetcode_question_108 Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Recurse: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode
2013-09-22 23:34:23 1182
原创 leetcode_question_107 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}
2013-09-22 23:19:16 1096
原创 leetcode_question_110 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 everynode never diff
2013-09-22 22:50:39 1258
原创 leetcode_question_117 Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constan
2013-09-22 22:26:48 1422
原创 leetcode_question_116 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.
2013-09-22 22:24:03 1322
原创 leetcode_question_123 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 ma
2013-09-22 21:59:25 1964
原创 leetcode_question_122 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
2013-09-22 21:03:01 3446
原创 leetcode_question_121 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
2013-09-22 20:42:04 1548
原创 leetcode_question_102 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
2013-09-22 00:14:15 1466
原创 leetcode_question_125 Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is no
2013-09-21 23:11:05 1348
原创 leetcode_question_124 Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return 6.
2013-09-21 11:42:30 1264 2
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人