![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 57
miao65272156
这个作者很懒,什么都没留下…
展开
-
leetcode - single number
class Solution { public: int singleNumber(int A[], int n) { int ret = 0; for(int i = 0; i < n; i++) { ret ^= A[i]; } return ret; } };原创 2014-05-22 19:49:11 · 269 阅读 · 0 评论 -
leetcode - Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.原创 2014-05-22 20:01:20 · 347 阅读 · 0 评论 -
leetcode - Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock原创 2014-05-24 11:15:43 · 604 阅读 · 0 评论 -
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].原创 2014-05-24 19:34:53 · 360 阅读 · 0 评论 -
leetcode - 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-06-07 19:47:51 · 241 阅读 · 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-06-07 20:29:26 · 298 阅读 · 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-24 13:37:48 · 543 阅读 · 0 评论 -
leetcode - Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2014-06-07 19:54:14 · 215 阅读 · 0 评论 -
leetcode - 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-06-07 22:09:00 · 246 阅读 · 0 评论 -
leetcode - Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321原创 2014-05-24 11:05:56 · 267 阅读 · 0 评论 -
leetcode - 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-06-07 20:52:24 · 350 阅读 · 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. 分析:跟硬币找零所用的贪心法lei原创 2014-06-07 21:56:04 · 322 阅读 · 0 评论 -
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.原创 2014-05-24 19:23:50 · 292 阅读 · 0 评论 -
leetcode - Linked List Cycle
Given a linked list, determine if it has a cycle in it. 分析:经典面试题,用原创 2014-05-24 20:14:09 · 315 阅读 · 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.原创 2014-05-24 15:37:27 · 505 阅读 · 0 评论 -
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. 分析:原创 2014-06-07 22:23:29 · 274 阅读 · 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-06-09 09:58:53 · 293 阅读 · 0 评论 -
leetcode - N-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions.原创 2014-06-09 10:54:53 · 383 阅读 · 0 评论 -
leetcode - N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle.原创 2014-06-09 10:32:39 · 277 阅读 · 0 评论 -
leetcode - Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 分析:原创 2014-06-09 11:15:49 · 307 阅读 · 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-05-31 20:15:51 · 361 阅读 · 0 评论 -
leetcode - Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.原创 2014-05-31 20:43:00 · 387 阅读 · 0 评论 -
leetcode - Remove Duplicates from Sorted List
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.原创 2014-05-31 20:56:40 · 364 阅读 · 0 评论 -
leetcode - Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2014-06-17 14:18:14 · 363 阅读 · 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-06-17 15:35:26 · 333 阅读 · 0 评论 -
leetcode - 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 (size that is greater or equal to m + n) to hold additional elements from原创 2014-06-17 14:30:00 · 395 阅读 · 0 评论 -
leetcode - 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原创 2014-06-17 14:46:26 · 354 阅读 · 0 评论 -
leetcode - 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 integers原创 2014-06-17 14:54:17 · 328 阅读 · 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-06-17 15:05:38 · 341 阅读 · 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? fenx原创 2014-06-17 15:45:48 · 290 阅读 · 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-06-17 14:35:46 · 279 阅读 · 0 评论 -
leetcode - 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.原创 2014-06-17 13:13:40 · 272 阅读 · 0 评论 -
leetcode - 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-06-17 13:40:03 · 289 阅读 · 0 评论 -
leetcode - 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.原创 2014-06-17 16:11:33 · 313 阅读 · 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].原创 2014-06-18 16:20:07 · 298 阅读 · 0 评论 -
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原创 2014-06-18 21:06:58 · 333 阅读 · 0 评论 -
leetcode - Unique Paths
A robot is located at the top-left corner of a m x n grid (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原创 2014-06-18 18:43:44 · 296 阅读 · 0 评论 -
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原创 2014-06-18 19:04:38 · 311 阅读 · 0 评论 -
leetcode-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-09-25 00:20:18 · 336 阅读 · 0 评论 -
leetcode-Substring with Concatenation of All Words
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)).原创 2014-09-25 16:36:45 · 278 阅读 · 0 评论