剑指offer
文章平均质量分 60
TiWalker
冷静思考,坚持努力,勇敢前行!
展开
-
LeetCode 22-Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "原创 2016-08-16 11:17:41 · 436 阅读 · 0 评论 -
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 assu原创 2016-09-27 09:13:04 · 277 阅读 · 0 评论 -
208. Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. class TrieNode { public: // Initialize your data s原创 2016-09-23 11:47:19 · 414 阅读 · 0 评论 -
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-09-23 11:41:02 · 290 阅读 · 0 评论 -
剑指offer(中位数-LeetCode4)
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1原创 2016-08-12 10:26:45 · 1825 阅读 · 1 评论 -
剑指offer(动态规划-LeetCode72)
LeetCode 72: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations perm原创 2016-08-11 10:14:36 · 1323 阅读 · 1 评论 -
剑指offer(两个栈实现队列)
使用两个栈实现一个队列。 栈是先进后出,队列是后进先出。如果只有一个栈那么是无法实现队列的,但是两个栈完全可以。代码如下: template class Cqueue { public: Cqueue(void); ~Cqueue(void); void appendTail(const T& node); T deleteHead(); private: stack原创 2016-08-10 10:00:33 · 622 阅读 · 0 评论 -
剑指offer(1)
设计一个类,我们只能生成该类的一个实例。 这是考设计模式的一道题,设计模式是面向对象程序设计的编程思想。参考大神的专栏:设计模式。单例模式倒不难,要求是在程序中只允许创建一个对象实例。 那么来看第一种解法了。 class Singleton1 { //实现单例模式,单线程可以保证只创建一个instance,但多线程下无法保证 priva原创 2016-08-08 17:14:45 · 347 阅读 · 0 评论 -
剑指offer(2)
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-08-10 09:30:46 · 480 阅读 · 0 评论 -
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 house原创 2016-08-21 15:01:29 · 368 阅读 · 0 评论 -
LeetCode 84. Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width o原创 2016-08-21 09:02:09 · 383 阅读 · 0 评论 -
LeetCode 376. Wiggle Subsequence
A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either pos原创 2016-08-20 19:41:08 · 1742 阅读 · 0 评论 -
72. Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:原创 2016-09-27 09:17:30 · 294 阅读 · 0 评论