- 博客(76)
- 收藏
- 关注
原创 [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 those hor
2015-07-30 09:51:36 396
原创 [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 only let
2015-07-27 23:24:44 1190
原创 [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. This time
2015-07-27 22:12:01 279
原创 [leetcode] 215.
题目: 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, return 5.N
2015-07-25 17:02:05 293
原创 [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 difference between nums[i] and nums[j] is at most t and the difference between i and
2015-07-25 16:19:48 267
原创 [leetcode] 219. Contains Duplicate II
题目: Given an array of integers and an integer k, find out whether there 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-07-24 15:28:20 250
原创 [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 elemen
2015-07-24 15:06:35 324
原创 [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 the total area
2015-07-24 10:29:10 345
原创 [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() – Return wh
2015-07-23 17:20:29 237
原创 [leetcode] 226.Invert Binary Tree
题目: Invert a binary tree.4/ \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 题意: 翻转二叉树。 思路: 这道题采用递归的思想,将左右子树分别反转,然后将左右子树对调。 代码如下:/** * Definitio
2015-07-23 17:04:49 260
原创 [leetcode] 210.Course Schedule II
题目: There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a
2015-07-22 22:36:03 244
原创 [leetcode] 209.Minimum Size Subarray Sum
题目: Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn’t one, return 0 instead.For example, given the array [2,3,1
2015-07-22 22:01:25 365
原创 [leetcode] 207.Course Schedule
题目: There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a
2015-07-20 10:45:28 362
原创 [leetcode] 206.Reverse Linked List
题目: Reverse a singly linked list. 题意: 反转单链表。 思路: 可以使用循环的方式,或者栈的方式,或者递归。 栈的方式是把每个元素依次入栈,出来的时候就是从尾到头的顺序。 递归的本质就是栈,此处不表。 代码如下: 注释部分是循环和栈的两个实现。/** * Definition for singly-linked list. * struct L
2015-07-20 00:23:09 247
原创 [leetcode] 188.Best Time to Buy and Sell Stock IV
题目: Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note: You may not en
2015-07-19 23:24:34 307
原创 [leetcode] 205.Isomorphic Strings
题目: 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 with another
2015-07-19 21:47:14 329
原创 [leetcode] 204.Count Primes
题目: Description:Count the number of prime numbers less than a non-negative number, n.题意: 找出小于n的所有素数。 思路: 采用筛选法。首先知道如果一个数不是素数,那么它一定可以表示成多个素数相乘,而且很明显这些素数肯定是比这个合数小。 每次第一个没删去的元素就是素数,接下来找该素数的所有倍数(倍数大于等
2015-07-19 01:20:28 326
原创 [leetcode] 203.Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5 题意: 删除链表中元素值等于某个值的所有节点。 代码如下:/**
2015-07-18 19:28:54 254
原创 [leetcode] 200.Number of Islands
题目: Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may as
2015-07-18 18:43:03 305
原创 [leetcode] 201.Bitwise AND of Numbers Range
题目: Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4. 题意: 给定一个区间,找出该区间所有元
2015-07-18 18:11:56 1161
原创 [leetcode] 202.Happy Number
题目: Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2015-07-18 17:53:59 314
原创 [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 wind
2015-07-18 15:52:55 317
原创 [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”].题意: 排序数组,不包含重复元素。返回每一个区间。区间就是元素连续相连的。 思路: 比较简单就是从前
2015-07-18 10:57:35 186
原创 [leetcode] 198.House Robber
题目: 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 adjacent h
2015-07-17 23:55:32 283
原创 [leetcode] 189.Rotate Array
题目: 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 you can,
2015-07-17 15:57:58 343
原创 [leetcode] 179.Largest Number
题目: Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very l
2015-07-16 17:48:56 249
原创 [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 and in O(n).
2015-07-16 14:43:31 345
原创 [leetcode] 173.Binary Search Tree Iterator
题目: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and
2015-07-16 14:08:03 274
原创 [leetcode] 172.Factorial Trailing Zeroes
题目: Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity. 题意: 给定一个整数n,返回n!的末尾的0的个数。 思路: 首先能够出现0是末尾是5的数乘上2的倍数或者末尾是0的数。而且是2的倍数的
2015-07-16 00:32:20 229
原创 [leetcode] 171.Excel Sheet Column Number
题目: Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28 题意: 把26进制的数转化为十进制。 代码比较简单,如下:class
2015-07-15 23:58:30 154
原创 [leetcode] 168.Excel Sheet Column Title
题目: Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB题意: 给定一个正数,返回它在excel中对应的列号。如上面所示,这是一个2
2015-07-15 23:45:19 193
原创 [leetcode] 164.Maximum Gap
题目: Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.You
2015-07-15 23:36:20 598
原创 [leetcode] 165.Compare Version Numbers
题目: Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and
2015-07-15 14:47:46 348
原创 [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 with value
2015-07-15 14:24:58 327
原创 [leetcode] 162.Find Peak Element
题目: A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that
2015-07-15 00:02:44 227
原创 [leetcode] 160.Intersection of Two Linked Lists
题目: 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-07-14 21:44:24 286
原创 [leetcode] 155.Min Stack
题目: 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
2015-07-14 17:37:33 296
原创 [leetcode] 154.Find Minimum in Rotated Sorted Array II
题目: Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unkno
2015-07-14 17:27:27 325
原创 [leetcode] 153.Find Minimum in Rotated Sorted Array
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in the array.
2015-07-14 15:43:30 357
原创 [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
2015-07-14 10:38:23 381
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人