自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode: Unique Paths

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach th

2013-05-31 18:36:27 405

原创 leetcode: Valid Parentheses

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

2013-05-30 14:24:23 470

原创 leetcode: Same Tree

Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /**

2013-05-30 13:57:26 886

原创 leetcode: Path Sum

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 binary tree and sum

2013-05-30 13:47:47 474

原创 leetcode: Minimum Window Substring

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example, S = "ADOBECODEBANC" T = "ABC" Minimum window is "BAN

2013-05-29 22:30:41 439

原创 leetcode: Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For

2013-05-29 20:05:43 894

原创 leetcode: Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be n

2013-05-29 01:30:46 486

原创 leetcode: Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeated number may be chosen from C unlimited

2013-05-28 12:45:19 553

原创 leetcode: Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]

2013-05-28 00:47:01 620

原创 leetcode: Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *

2013-05-24 18:35:52 638

原创 leetcode: 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

2013-05-24 18:08:21 796

转载 static_cast与dynamic_cast转换

original web:  一 C语言中存在着两种类型转换: 隐式转换和显式转换 隐式转换:不同数据类型之间赋值和运算,函数调用传递参数……编译器完成 char ch;int i = ch; 显示转换:在类型前增加 :(Type)变量 对变量进行的转换。用户显式增加 char *pc = (char*)pb;void *ps = (void

2013-05-24 14:41:23 1789

原创 leetcode: Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. class Solution { public: bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO

2013-05-24 11:27:56 532

转载 中介者模式

转自出处  一、引子  中介在现实生活中并不陌生,满大街的房屋中介、良莠不齐的出国中介……。它们的存在是因为它们能给我们的生活带来一些便利:租房、买房用不着各个小区里瞎转;出国留学也不用不知所措。 中介者模式在程序设计中也起到了类似的作用。 二、定义与结构 GOF给中介者模式下的定义是:用一个中介对象来封装一系列的对象交互。中介者使各对象不需要

2013-05-24 11:17:09 4787

原创 leetcode: Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant

2013-05-24 10:51:00 463

转载 最大子矩阵问题

转自出处 最大子矩阵问题: 问题描述:(具体见http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=1050)    给定一个n*n(0 Example:  0 -2 -7  0   9  2 -6  2  -4  1 -4  1  -1  8  0 -2  其中左上角的子矩阵:  9 2  -4 1

2013-05-23 23:02:54 465

转载 Builder模式

转自出处     最近重读GOF的《设计模式》,读到Builder模式的时候,发现还是不能领悟;网上搜了下其他人的解释,发现很多人都用错了Builder模式,结构形似Builder,实际上却更像Template、或者Factory Method,或者四不像,并没有体现出Builder模式的思想和威力;通过对比学习,也逐渐加深了我对Builder模式的认识,于是就有了这篇文章。

2013-05-23 20:49:05 791

转载 组合模式

转自出处 本文介绍设计模式中的组合(Composite)模式的概念,用法,以及实际应用中怎么样使用组合模式进行开发。 Composite模式的概念 Composite模式是构造型的设计模式之一,通过递归手段来构造诸如文件系统之类的树形的对象结构;Composite模式所代表的数据构造是一群具有统一接口界面的对象集合,并可以通过一个对象来访问所有的对象(遍历)。

2013-05-22 22:38:15 518

转载 visitor模式

转自出处 "众口难调"出自宋·欧阳修《归田录》卷一:"补仲山之衮,虽曲尽于巧心;和傅说之羹,实难调于众口。"其原意是各人的口味不同,很难做出一种饭菜使所有的人都感到好吃。众口是否真的难调呢?其实有个不错的办法可以解决众口难调的问题,那就是吃"自助餐"。 面对众口难调的问题去吃"自助餐"已经不是什么新鲜事,承办一个几百人、几千人的会议往往采用的都是自助餐的方式,让来宾各取所需

2013-05-22 22:27:56 1076

转载 装饰模式

转自出处 现在我们来学习装饰模式。说实话,真不想写这个,因为提到这个装饰,程序员就很伤感(我也是),就想到了遥远地她和虚无缥缈地房子。房子都还没着落,谈什么装修和粉饰啊。一堵粗糙的墙,刷上白白地粉,再贴上几张壁画,整个一焕然一新。多美的事啊。哎,既然想到了,就咬着牙多想会,至少心里还有个期盼。真心祝愿大家看完这篇文章后都能够梦想成真。   生活中的装饰是很好理解的,我们打两个比方

2013-05-22 21:25:16 463

原创 leetcode: Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found

2013-05-21 22:35:45 465

原创 leetcode: Balanced Binary Tree

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never diff

2013-05-20 13:42:19 1083

原创 leetcode: 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 w

2013-05-20 10:33:51 811

原创 leetcode: 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exa

2013-05-18 23:59:23 752

原创 leetcode: Simplify Path

Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" class Solution { public: string simplifyPath(s

2013-05-18 23:34:42 773 1

原创 leetcode: Subsets

Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For

2013-05-18 22:47:01 1123

原创 leetcode: Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [

2013-05-18 00:27:03 871

原创 leetcode: Restore IP Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Orde

2013-05-17 14:48:00 668

原创 leetcode: Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1

2013-05-16 23:40:59 649

原创 leetcode: Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

2013-05-15 23:44:38 600

原创 leetcode: 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: "((()))", "(()())", "(())()", "()(())", "()

2013-05-15 19:06:01 790

原创 leetcode: Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \

2013-05-15 13:27:37 644

原创 leetcode: Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1

2013-05-15 12:58:38 470

原创 leetcode: Best Time to Buy and Sell Stock II

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 as many transactions as you like (ie, buy

2013-05-14 23:08:19 638

原创 leetcode: Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock

2013-05-14 22:51:46 667

原创 leetcode: Interleaving String

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc",

2013-05-14 18:35:05 1347

原创 leetcode: Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. #define MAX_LEN 0xFFFF class Solution { public: string longestCommonPrefix(vector &strs) { /

2013-05-14 00:16:16 680

原创 leetcode: Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. /** * Definition for singly-linked list. * struct L

2013-05-13 23:56:03 936

原创 leetcode: Maximal Rectangle

Largest Rectangle in HistogramApr 23 '121499 / 4823 Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangl

2013-05-11 22:39:03 880

原创 leetcode: Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal tox. You should preserve the original relative order of the nodes in each o

2013-05-11 00:41:39 469

空空如也

空空如也

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

TA关注的人

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