自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [leetcode] 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 off as 

2016-03-31 20:54:42 237

原创 [leetcode] 241. Different Ways to Add Parentheses

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1

2016-03-30 16:16:16 500

原创 [leetcode] 50. Pow(x, n)

Implement pow(x, n).这道题是实现pow(x, n),题目难度为Medium。将x的乘积(ret)每次翻番同时将计数(cnt)翻倍,cnt的二倍超出n时,重新计算pow(x, n-cnt),这样ret * pow(x, n-cnt)即是最终的结果。n为负数时用1除以相反数的计算结果即可。测试用例中n的测试数据有INT_MIN,这里直接包了一层函数用

2016-03-29 11:53:58 329

原创 [leetcode] 69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x.这道题是计算平方根,题目难度为Medium。1以上的数字平方根小于等于自身的一半(取整),可以采用二分查找法在1和x/2之间查找比对来确定平方根。具体代码:class Solution {public: int myS

2016-03-29 09:00:00 315

原创 [leetcode] 53. 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

2016-03-28 21:02:55 344

原创 [leetcode] 169. 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 majority element

2016-03-26 17:26:58 375

原创 [leetcode] 138. Copy List with Random Pointer

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.这道题是deep copy链表,题目难度为H

2016-03-25 19:48:25 461 1

原创 [leetcode] 152. 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

2016-03-24 10:28:06 386

原创 [leetcode] 64. Minimum Path Sum

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at

2016-03-23 11:09:15 287

原创 [leetcode] 27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2016-03-22 10:58:45 321

原创 [leetcode] 146. LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if

2016-03-21 19:22:52 469

原创 [leetcode] 231. Power of Two

Given an integer, write a function to determine if it is a power of two.这道题是判断数字是否是2的乘方,题目难度为Easy。int范围内2的乘方只有31个,逐个判断即可,具体代码:class Solution {public: bool isPowerOfTwo(int n) {

2016-03-20 21:25:03 423

原创 [leetcode] 338. Counting Bits

Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5

2016-03-18 11:57:14 3243

原创 [leetcode] 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.这道题是将已排序链表转化为高度平衡的二叉搜索树,题目难度为Medium。题目和108题(传送门)相关,感兴趣的同学可以先看下108题。题目要求BST高

2016-03-17 21:14:25 439

原创 [leetcode] 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.这道题是将已排序数组转化为高度平衡的二叉搜索树,题目难度为Medium。要求BST高度平衡,所以要取当前区间的中点元素作为当前子树的根节点,左右两边的元素分别组成左子树和右子树,这样通过

2016-03-17 20:21:35 442

原创 [leetcode] 9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string,

2016-03-17 11:10:04 220

原创 [leetcode] 326. Power of Three

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?这道题是判断数字是否是3的乘方,题目难度为Easy。题目限定不能循环或递归,有点无从下手,看了

2016-03-15 08:52:01 401

原创 [leetcode] 335. Self Crossing

You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2]metres to the south, x[3] metres to the east and so

2016-03-14 17:39:42 383

原创 [leetcode] 82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-

2016-03-13 19:08:10 372

原创 [leetcode] 337. House Robber III

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour

2016-03-12 20:20:56 3510

原创 [leetcode] 83. 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.这道题是删除已排序链表中重复值

2016-03-11 10:34:09 285

原创 [leetcode] 236. Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node

2016-03-09 18:42:56 210

原创 [leetcode] 235. Lowest Common Ancestor of a Binary Search Tree

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw

2016-03-08 17:16:22 292

原创 [leetcode] 11. 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

2016-03-07 15:16:58 316

原创 [leetcode] 312. Burst Balloons

Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you will get num

2016-03-05 21:16:59 456

原创 [leetcode] 216. Combination Sum III

Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi

2016-03-04 10:49:15 240

原创 [leetcode] 40. Combination Sum II

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina

2016-03-03 21:52:08 347

原创 [leetcode] 39. Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb

2016-03-03 20:37:12 391

空空如也

空空如也

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

TA关注的人

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