自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Search a 2D Matrix II -- leetcode

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.Integers in

2015-09-29 21:51:36 368

原创 Delete Node in a Linked List -- leetcode

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 with val

2015-09-25 11:26:58 328

原创 Lowest Common Ancestor of a Binary Tree -- leetcode

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

2015-09-25 11:06:17 325

原创 Lowest Common Ancestor of a Binary Search Tree -- leetcode

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

2015-09-22 16:32:16 347

原创 Palindrome Linked List -- leetcode

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?基本思路:1. 先用快慢指针,找到链表的中间结点。2. 将后半段进行逆转3. 将前半段和经过逆转的后半段进行逐个比较。此题不得不修改

2015-09-20 17:34:07 359

原创 Number of Digit One -- leetcode

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 followin

2015-09-19 21:04:53 584

原创 Implement Queue using Stacks -- leetcode

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 element.empty(

2015-09-18 14:54:36 315

原创 Power of Two -- leetcode

Given an integer, write a function to determine if it is a power of two.基本思路:1,指数函数的结果,肯定是 > 0的。 故首先排除掉负数和0.2, 2^x (x为整数)结果中,如果用二进制表示,那么其中只有1个bit位为1,其他全为0.       2的各次乘方,相当于把1向左移几次。3,  

2015-09-18 14:07:03 369

原创 Kth Smallest Element in a BST -- leetcode

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:What if the

2015-09-16 18:14:04 302

原创 Majority Element II -- leetcode

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.基本思路:Boyer-Moore Majority Vote algorith

2015-09-16 17:33:41 421

原创 Summary Ranges -- leetcode

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"].class Solution {public: vector summa

2015-09-15 14:50:50 305

原创 Basic Calculator II -- leetcode

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

2015-09-15 10:11:07 360

原创 Invert Binary Tree -- leetcode

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1算法一,dfs递归基本思路,就是将每一个节点的左右孩子指针互换。/** * Definition for a binary tree

2015-09-13 19:38:02 306

原创 Implement Stack using Queues -- leetcode

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() -- Return whet

2015-09-13 17:52:29 327

原创 Basic Calculator -- leetcode

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 and em

2015-09-13 11:59:42 356

原创 Rectangle Area -- leetcode

Find the total area covered by two rectilinear rectangles in a2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total a

2015-09-10 17:02:58 401

原创 Count Complete Tree Nodes -- leetcode

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 completely filled,

2015-09-10 15:36:03 401

原创 Maximal Square -- leetcode

Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 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 0 0 1 0

2015-09-07 16:47:17 330

原创 Contains Duplicate II -- leetcode

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

2015-09-03 18:16:54 323

原创 The Skyline Problem -- leetcode

基本思路:第七版以buildings的边界为处理单位。以此边界x坐标得到输出点的x坐标,以此边界上的房屋最高的高度为输出点的y坐标。在这些点中,去除掉,和上次输出坐标中高度相同的点。具体做法为,1. 先取点,房屋左边界和其高度为一个点;房屋右边界和其高度为一个点。由于左边界和右边界时处理时,要有所区分。 可以将高度一个设置为正,一个设置为负。以示区分。2. 要将左边界的

2015-09-03 17:03:58 484

空空如也

空空如也

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

TA关注的人

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