自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 收藏
  • 关注

原创 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

2016-05-31 16:01:25 179

原创 155. Min Stack

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

2016-05-26 13:25:00 149

原创 204. Count Primes

Description: Count the number of prime numbers less than a non-negative number, n. 在leetcode上全程看完了hint…… class Solution { public: int countPrimes(int n) { vector isPrime(n,true);

2016-05-26 11:14:03 137

原创 203. Remove Linked List Elements

Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 思路:用两个指针分别指向现在和前一个结点,发现v

2016-05-24 16:25:22 135

原创 278. First Bad Version

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the

2016-05-24 12:43:59 149

原创 7. Reverse Integer&&190. Reverse Bits

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 思路:并没有什么特殊的……用一个long int来防止溢出并检验溢出 class Solution { public: int reverse(int x) { int n=

2016-05-24 11:05:03 170

原创 26. Remove Duplicates from Sorted Array&&27. Remove Element

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

2016-05-23 15:53:31 147

原创 66. 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. 这题我坚信leetcode出了问题,欢迎

2016-05-23 15:51:04 315

原创 118. Pascal's Triangle&&119. Pascal's Triangle II

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] ] 解法:没有什么,用一个成员是vec

2016-05-23 15:45:43 175

原创 189. Rotate Array

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]. 思路:这题有很多种方法。自己写了一种,主要就是先把5、6、7接到另一个vector上,再把

2016-05-21 15:44:25 126

原创 70. 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? //这题根本上来说是一个斐波那契数列。一个台阶有一种方法

2016-05-19 14:59:23 176

原创 191. Number of 1 Bits

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000

2016-05-19 12:00:23 168

原创 226. Invert Binary Tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ clas

2016-05-18 16:26:47 161

原创 110. Balanced Binary Tree

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 sub

2016-05-18 16:16:32 216

原创 206. Reverse Linked List&&92. Reverse Linked List II

依然不想赘述题目…… 206一开始想了有点久,因为网上很多答案是没有 * 的,就像这样  ListNode pre = head   宝宝就有点没拐过弯来。改天要复习一下*和&。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *

2016-05-17 14:53:03 175

原创 235. Lowest Common Ancestor of a Binary Search Tree&&236. Lowest Common Ancestor of a Binary Tree

并不想赘述题……直接记代码。 235是一个二叉搜索树,那么很明显可以利用的条件就是左边小,右边大。我用的是递归。需要注意的是二叉树要记得考虑NULL的特殊情况。 class Solution { public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { if(p=

2016-05-17 14:48:05 170

原创 169.Majority Element && 229. Majority Element II

Majority Element Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the

2016-05-13 11:52:44 178

原创 344. Reverse String

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 这个很简单啦。。。第一题

2016-05-06 20:45:43 154

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除