LeetCode
gejun123456789
这个作者很懒,什么都没留下…
展开
-
[LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one. class Solution { public: int singleNumber(int A[], int n) { int s=0; int i;原创 2014-03-16 11:33:49 · 371 阅读 · 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. /** * Def原创 2014-03-16 12:00:54 · 369 阅读 · 0 评论 -
[LeetCode] Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 class Solution { public: int reverse(int x) { int s=0; int a=0; if(x<0)原创 2014-03-16 12:09:11 · 349 阅读 · 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-03-16 12:25:41 · 416 阅读 · 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. /** * Definition for binary tree原创 2014-03-16 11:43:12 · 347 阅读 · 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. class Solution { public: int numTrees原创 2014-03-18 00:02:07 · 381 阅读 · 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-18 00:19:28 · 344 阅读 · 0 评论