自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [leetcode 299] Bulls and Cows

Quesiton:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide

2015-11-30 22:46:52 330

原创 [leetcode 67] Add Binary

Question:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".分析:从最低位开始计算(字符串的最高位开始),判断‘1’ ‘0’即可。代码:class Solutio

2015-11-30 21:34:23 351

原创 [leetcode 14] Longest Common Prefix

Quesiton:Write a function to find the longest common prefix string amongst an array of strings.分析:题目要求写一个函数,返回所有字符串的最常公共前缀。如果只有一个字符串,返回本身即可;若果字符串数量大于等于2,依次比较即可。先比较前两个,前缀的长度肯定小于等于这两个字符串的最

2015-11-26 23:29:32 328

原创 [leetcode 38] Count and Say

Question: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 

2015-11-26 22:50:55 297

原创 [leetcode 290] Word Pattern

Question:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty

2015-11-26 21:56:36 796

原创 [leetcode 205] Isomorphic Strings

Question:Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced wi

2015-11-19 23:03:35 424

原创 [leetcode 203] Remove Linked List Elements

Question:Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5分析:对单链表

2015-11-19 21:53:57 398

原创 [leetcode 276] Paint Fence

Question:There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more than two adjacent fence posts have the same color.

2015-11-19 14:05:50 3042

原创 [leetcode 20] Valid Parentheses

Question:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" a

2015-11-19 13:06:28 354

原创 [leetcode 223] Rectangle Area

Question:Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Rectangle

2015-11-19 12:33:12 503

原创 [leetcode 249] Group Shifted Strings

Question:Given a string, we can "shift" each of its letter to its successive letter, for example:"abc" -> "bcd". We can keep "shifting" which forms the sequence:"abc" -> "bcd" -> ... -> "xyz"Giv

2015-11-17 09:10:21 2325

原创 [leetcode 219] Contains Duplicate II

Question:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k

2015-11-13 23:02:41 337

原创 [leetcode 19] Remove Nth Node From End of List

Question:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node fr

2015-11-13 21:59:09 288

原创 [leetcode 58] Length of Last Word

class Solution {private:    vector split(string s, string pattern){        int pos;        vector result;        s += pattern;        for(int i = 0; i             pos = s.find(pattern,i)

2015-11-13 21:20:53 326

原创 [leetcode 36] Valid Sudoku

Question:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A pa

2015-11-07 18:15:27 376

原创 [leetcode 190] Reverse Bits

Question:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in bina

2015-11-07 15:46:58 361

原创 [leetcode 88]Merge Sorted Array

Question:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n

2015-11-06 19:58:07 296

原创 [leetcode 157] Read N Characters Given Read4

Question:The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 charact

2015-11-06 14:04:51 1344

原创 [leetcode 111]Minimum Depth of Binary Tree

Question:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.分析:1、root = NULL,深度

2015-11-05 21:54:53 432

原创 [leetcode 160]Intersection of Two Linked Lists

Question:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A:          a1 → a2                   ↘     

2015-11-04 23:19:28 326

原创 [leetcode 9] Palindrome Number

Question:Determine whether an integer is a palindrome.Do this without extra space.分析:回文数字,将数字倒过来和原来数字一样。比如101,5,12321等。注意与266题的区别。只要将原来数字的逆序数字求出来即可。代码:class Solution {public:

2015-11-04 22:48:02 316

原创 [leetcode 112]Path Sum

Question:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binar

2015-11-04 22:05:00 421

原创 [leetcode 119] Pascal's Triangle II

Question:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?

2015-11-04 21:41:02 300

原创 [leetcode 102] Binary Tree Level Order Traversal

Question:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7},    3   / \

2015-11-04 20:32:05 313

原创 [leetcode 172] Factorial Trailing Zeroes

Question:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.要求输入为n,求n!中尾数0的个数。要求时间复杂度为O(log(n));分析:暴力法可以是先求出n

2015-11-03 22:32:07 351

原创 [leetcode 225] Implement Stack using Queues

Question:Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty()

2015-11-02 23:04:52 355

原创 [leetcode 270] Closest Binary Search Tree Value

Question:Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:Given target value is a floating point.You are guaranteed t

2015-11-02 22:31:59 634

原创 [leetcode 118]Pascal's triangle

Question: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]]Solution:

2015-11-02 22:05:04 330

原创 [leetcode 198]House Robber

Question:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adj

2015-11-02 21:46:59 321

原创 [leetcode 66]Pluss One

class Solution {public: vector plusOne(vector& digits) { bool isNine = true; for(int i : digits) if(i != 9) isNine = false; if(isNine){

2015-11-01 18:43:16 381

原创 [leetcode 26]Remove Duplicates from Sorted Array

class Solution {public: int removeDuplicates(vector& nums) { vector::iterator it; if(nums.empty()) return 0; for(it = nums.begin()+1; it != nums.end();)

2015-11-01 18:03:46 316

原创 [leetcode 107]Binary Tree Level Order Traversal II

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

2015-11-01 18:02:32 375

原创 [leetcode 27]Remove Element

class Solution {public: int removeElement(vector& nums, int val) { vector::iterator it; if(nums.size() == 0) return 0; for(it = nums.begin(); it != nums.end();

2015-11-01 18:00:29 323

原创 [leetcode 101]Symmetric 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

2015-11-01 17:58:46 322

原创 [leetcode 231]Power of Two

class Solution {public: bool isPowerOfTwo(int n) { /* if(n <= 0) return false; if(n == 1) return true; if(n%2 == 1) return false;

2015-11-01 17:57:32 324

原创 [leetcode 110]Balanced 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

2015-11-01 17:55:52 382

原创 [leetcode 246] Strobogrammatic Number

Question:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to determine if a number is strobogrammatic. The number is rep

2015-11-01 12:06:14 1158

空空如也

空空如也

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

TA关注的人

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