上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页

2014年3月21日

类的sizeof

摘要: 转自http://blog.csdn.net/valerie_7/article/details/67576641、空类的sizeof是1。空类是指没有成员的类,类中的函数不占空间,除非是虚函数。如: class A { public: A(){} ~A(){} void fun(){} };sizeof(A)是1.注: class A1 { public: A1(){} ~A1(){} void fun(){}char a[0]; };sizeof(A1)也是1.(VC6.0下编译)2、若类中包含成员,则类对象的大小只包括其中非静态成员经过对齐所占的空间,对齐方式和结构体相同。如:class 阅读全文

posted @ 2014-03-21 21:20 pengyu2003 阅读(296) 评论(0) 推荐(1)

Implement strStr()

摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.用KMPclass Solution {public: char *strStr(char *haystack, char *needle) { int size = 0; for(;haystack[size]!='\0' ;size++); int size_needle =0; wh... 阅读全文

posted @ 2014-03-21 13:25 pengyu2003 阅读(162) 评论(0) 推荐(0)

KMP很清楚的一篇解释

摘要: 转自http://billhoo.blog.51cto.com/2337751/411486以下为原博直接粘贴相信很多人(包括自己)初识KMP算法的时候始终是丈二和尚摸不着头脑,要么完全不知所云,要么看不懂书上的解释,要么自己觉得好像心里了解KMP算法的意思,却说不出个究竟,所谓知其然不知其所以然是也。 经过七八个小时地仔细研究,终于感觉自己能说出其所以然了,又觉得数据结构书上写得过于简洁,不易于初学者接受,于是决定把自己的理解拿出来与大家分享,希望能抛砖引玉,这便是Bill写这篇文章想要得到的最好结果了-----------------------------------谨以此文,献给刚接触 阅读全文

posted @ 2014-03-21 10:24 pengyu2003 阅读(258) 评论(0) 推荐(0)

2014年3月19日

Best Time to Buy and Sell Stock II

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at 阅读全文

posted @ 2014-03-19 16:47 pengyu2003 阅读(104) 评论(0) 推荐(0)

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], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if you are a... 阅读全文

posted @ 2014-03-19 16:19 pengyu2003 阅读(168) 评论(0) 推荐(0)

Populating Next Right Pointers in Each Node

摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文

posted @ 2014-03-19 16:02 pengyu2003 阅读(189) 评论(0) 推荐(0)

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 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6click to show hints.刚开始想偷懒想把几个... 阅读全文

posted @ 2014-03-19 15:27 pengyu2003 阅读(109) 评论(0) 推荐(0)

Binary Tree Level Order Traversal II

摘要: Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its bottom-up level order traversal as:[ [15,7] [9,20], [3],]先查看有... 阅读全文

posted @ 2014-03-19 14:58 pengyu2003 阅读(101) 评论(0) 推荐(0)

2014年3月17日

Binary Tree Level Order Traversal

摘要: Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its level order traversal as:[ [3], [9,20], [15,7]]用lev记录当前树到了第几层。/** * Definition for binary... 阅读全文

posted @ 2014-03-17 22:28 pengyu2003 阅读(143) 评论(0) 推荐(0)

Validate Binary Search Tree

摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文

posted @ 2014-03-17 22:20 pengyu2003 阅读(120) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页

导航