摘要: http://oj.leetcode.com/problems/binary-tree-inorder-traversal/ 1 vector inorderTraversal(TreeNode *root) { 2 stack nextstep; 3 vector res; 4 TreeNode *p=root; 5 TreeNode *DIRTY = new TreeNode(0); 6 bool isMid = true; 7 while(p){ 8 if(p->rig... 阅读全文
posted @ 2013-11-29 17:00 沙茶面 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 原文:http://www.cnblogs.com/morewindows/archive/2011/08/13/2137415.html快速排序由于排序效率在同为O(N*logN)的几种排序方法中效率较高,因此经常被采用,再加上快速排序思想----分治法也确实实用,因此很多软件公司的笔试面试,包括像腾讯,微软等知名IT公司都喜欢考这个,还有大大小的程序方面的考试如软考,考研中也常常出现快速排序的身影。总的说来,要直接默写出快速排序还是有一定难度的,因为本人就自己的理解对快速排序作了下白话解释,希望对大家理解有帮助,达到快速排序,快速搞定。快速排序是C.R.A.Hoare于1962年提出的一种 阅读全文
posted @ 2013-11-29 16:50 沙茶面 阅读(158) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/ 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 int tmp = 0; 5 for(int i = 1;i < n;++i){ 6 if(A[i] == A[i-1]) ++tmp; 7 A[i-tmp] = A[i]; 8 } 9 retur... 阅读全文
posted @ 2013-11-29 12:05 沙茶面 阅读(80) 评论(0) 推荐(0) 编辑
摘要: http://oj.leetcode.com/problems/remove-element/!特征向量的思想,尽管有点大材小用,但是我的确是从djstla中获得的灵感。 1 class Solution { 2 public: 3 int removeElement(int A[], int n, int elem) { 4 int *b = new int[n+1]; 5 b[0] = 0; 6 for(int i = 0;i < n;++i){ 7 if(A[i] == elem){ 8 ... 阅读全文
posted @ 2013-11-29 11:33 沙茶面 阅读(201) 评论(0) 推荐(0) 编辑