自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

魔豆(Magicbean)的博客

分享计算机专业的相关知识

  • 博客(71)
  • 收藏
  • 关注

原创 [Leetcode] 250. Count Univalue Subtrees 解题报告

题目:Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given binary tree, 5

2017-06-30 16:56:07 922

原创 [Leetcode] 249. Group Shifted Strings 解题报告

题目: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"

2017-06-30 16:12:02 753

原创 [Leetcode] 248. Strobogrammatic Number III 解题报告

题目:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Write a function to count the total strobogrammatic numbers that exist in the ran

2017-06-30 15:42:29 1048

原创 [Leetcode] 247. Strobogrammatic Number II 解题报告

题目:A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).Find all strobogrammatic numbers that are of length = n.For example,Given n

2017-06-30 15:10:17 978

原创 [Leetcode] 246. Strobogrammatic Number 解题报告

题目: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 repre

2017-06-30 14:51:14 505

原创 [Leetcode] 245. Shortest Word Distance III 解题报告

题目:This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as word2.Given a list of words and two words word1 and word2, return the shortest dista

2017-06-30 10:46:26 460

原创 [Leetcode] 244. Shortest Word Distance II 解题报告

题目:This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How

2017-06-30 10:34:27 749

原创 [Leetcode] 243. Shortest Word Distance 解题报告

题目:Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list.For example,Assume that words = ["practice", "makes", "perfect", "c

2017-06-30 10:18:09 416

原创 [Leetcode] 242. Valid Anagram 解题报告

题目: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:Yo

2017-06-30 10:00:35 290

原创 [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 *.Exam

2017-06-30 09:51:31 387

原创 [Leetcode] 240. Search a 2D Matrix II 解题报告

题目:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Int

2017-06-30 09:27:26 341

原创 [Leetcode] 239. Sliding Window Maximum 解题报告

题目:Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding

2017-06-29 18:05:20 679

原创 [Leetcode] 238. Product of Array Except Self 解题报告

题目:Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division

2017-06-28 16:34:55 338

原创 [Leetcode] 237. Delete Node in a Linked List 解题报告

题目:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node w

2017-06-28 16:13:10 223

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

2017-06-28 15:59:58 451

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

2017-06-28 15:30:26 291

原创 [Leetcode] 234. Palindrome Linked List 解题报告

题目:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?思路:如果不限制O(1)的时间复杂度,那么方法就非常多了。既然限制了空间复杂度,那么可以有如下几个步骤来实现:1)用快慢指针同时走,来

2017-06-28 15:00:55 317

原创 [Leetcode] 233. Number of Digit One 解题报告

题目:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the

2017-06-26 17:16:58 377

原创 [Leetcode] 232. Implement Queue using Stacks 解题报告

题目:Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front eleme

2017-06-26 16:57:22 310

原创 [Leetcode] 231. Power of Two 解题报告

题目:Given an integer, write a function to determine if it is a power of two.思路:2的幂的二进制表示有一个特点,就是除了最高位是1之外,其余的位置上都是0,依据这个特点,可以设计如下两个算法:1、逐位判断:依次获取n的非最高位的值,一旦发现不是0,就返回false。这在算法实现上可以采用&和>>来实现。

2017-06-26 16:32:46 259

原创 [Leetcode] 230. Kth Smallest Element in a BST 解题报告

题目:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ? k ? BST's total elements.Follow up:Wh

2017-06-26 14:35:21 310

原创 [Leetcode] 229. Majority Element II 解题报告

题目:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.思路:1、Partition方法:可以调用基本快速排序中的partition

2017-06-26 14:19:11 1317

原创 [Leetcode] 228. Summary Ranges 解题报告

题目:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].思路:思路简单:看看当前数字是否和前一个数字相差1,如果是,则更新当前区间;否则

2017-06-26 13:34:05 291

原创 [Leetcode] 227. Basic Calculator II 解题报告

题目:Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer divisi

2017-06-26 11:18:04 367

原创 [Leetcode] 226. Invert Binary Tree 解题报告

题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by M

2017-06-26 10:41:48 233

原创 [Leetcode] 225. Implement Stack using Queues 解题报告

题目: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() -- Re

2017-06-26 10:34:57 289

原创 [Leetcode] 224. Basic Calculator 解题报告

题目:Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers

2017-06-26 09:52:45 670

原创 [Leetcode] 223. Rectangle Area 解题报告

题目: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.Assume that

2017-06-23 16:38:43 367

原创 [Leetcode] 222. Count Complete Tree Nodes 解题报告

题目:Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completel

2017-06-23 16:20:58 322

原创 [Leetcode] 221. Maximal Square 解题报告

题目:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11

2017-06-23 11:08:32 601

原创 [Leetcode] 220. Contains Duplicate III 解题报告

题目:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute 

2017-06-23 10:44:29 379

原创 [Leetcode] 219. Contains Duplicate II 解题报告

题目: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 absolute difference between i and j i

2017-06-23 10:13:35 267

原创 [Leetcode] 218. The Skyline Problem 解题报告

题目:A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the bui

2017-06-23 10:00:46 1535

原创 [Leetcode] 217. Contains Duplicate 解题报告

题目:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every ele

2017-06-23 09:15:25 234

原创 [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.Example 1

2017-06-22 17:11:44 243

原创 [Leetcode] 215. Kth Largest Element in an Array 解题报告

题目:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, r

2017-06-22 11:54:15 488

原创 [Leetcode] 214. Shortest Palindrome 解题报告

题目:Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.

2017-06-20 15:22:06 385

原创 [Leetcode] 213. House Robber II 解题报告

题目:Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention.

2017-06-20 11:00:53 348

原创 [Leetcode] 212. Word Search II 解题报告

题目:Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are

2017-06-19 15:43:55 476

原创 [Leetcode] 211. Add and Search Word - Data structure design 解题报告

题目:Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing

2017-06-19 15:07:43 395

空空如也

空空如也

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

TA关注的人

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