自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetceode_8_String to Integer (atoi)_(C++)(easy)

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 ca

2016-05-12 17:59:23 369

原创 leetcode_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-11 11:01:30 264

原创 leetcode_155_Min Stack(C++)(easy)

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-11 10:35:14 353

原创 leetcode_168_Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 思路:就是将十进制

2016-05-11 09:16:22 244

原创 leetcode_204_Count Primes(C++)(easy)

Description:Count the number of prime numbers less than a non-negative number, n.计算小于n的素数个数思路:维基百科https://en.wikipedia.org/wiki/Sieve_of_Eratosthenesclass Solution {public: 

2016-05-07 15:35:07 297

原创 leetcode_13_Roman to Integer(C++)(easy)

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路一:首先观察罗马数字Ⅰ、Ⅱ、Ⅲ、Ⅳ、Ⅴ、Ⅵ、Ⅶ、Ⅷ、Ⅸ、Ⅹ、Ⅺ、Ⅻ(1-12)。对于Ⅳ,当1出现在5的左侧时是4,即做减法。对于Ⅵ,1出现在5右侧是6,做加法。

2016-05-06 17:39:36 438

原创 leetcode_169_Majority Element(C++)(easy)

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 majority element

2016-05-06 17:11:45 392

原创 leetcode_263_Ugly Number(C++)(easy)

Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc

2016-04-27 15:39:57 270

原创 leetcode_344_ Reverse String(C++)(easy)

Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".思路:字符串可以类似数组一样通过下标方式访问,如s[1] = 'e'  因此可以很容易将字符串逆置。class Solution {

2016-04-27 14:59:19 622

原创 leetcode_171_ Excel Sheet Column Number(C++)(easy)

Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...

2016-04-19 11:21:19 262

原创 leetcode_100_Same Tree (C++)(easy)

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.思路:判断两个二叉树

2016-04-19 11:01:31 266

原创 leetcode_226_Invert Binary Tree(C++)(easy)

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1思路一:利用递归的思想/** * Definition for a binary tree node. * struct TreeNo

2016-04-18 11:44:43 226

原创 leetcode_104._Maximum Depth of Binary Tree(C++)(easy)

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.思路一: 可以利用递归的方式/** * Defi

2016-04-18 10:40:16 206

原创 leetcode_324_Power of Four(C++)(easy)

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.思路:得益于Power of two  首先确定该数大于零并且满足(num

2016-04-18 09:59:24 278

原创 leetcode_268_Missing Number(Medium)

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.思路:对于0-n的数列,应用求和公式为( 0 +

2016-03-30 13:59:43 215

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

2016-03-29 14:49:45 228

原创 leetcode_191_Number of 1 Bits(easy)(C++)

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 000000

2016-03-29 14:44:49 278

原创 leetcode_326_Power of Three(easy)(C++)

Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?思路:在一个double类型的数字上加0.5取整强制转换成int类型就是取下整或上整class Sol

2016-03-24 12:57:14 301

原创 leetcode_231_Power of Two(easy)(C++)

Given an integer, write a function to determine if it is a power of two.思路:2的power二进制都是最高位为1低位全0。所以n 与 n-1相与操作后应该是0

2016-03-24 11:30:15 296

原创 leetcode_328_Odd Even Linked List(easy)(C++)

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in

2016-03-24 10:29:21 277

原创 leetcode_206_Reverse Linked List(easy)(C++)

Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?思路:使用头插法迭代插入

2016-03-23 21:43:17 291

原创 leetcode_258_Add Digit(easy)(C++)

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on

2016-03-20 10:27:37 304

原创 leetcode_242_Valid Anagram(easy)(C++)(Java)

Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may a

2016-03-19 13:23:26 204

原创 leetcode_189_Rotate Array(easy)(C++)

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].Note:Try to come up as many solutions as yo

2016-03-16 14:05:40 178

空空如也

空空如也

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

TA关注的人

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