![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
文章平均质量分 67
mmshixing
这个作者很懒,什么都没留下…
展开
-
leetcode-T7 Reverse digits of an integer
题目要求:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321解:#define INT_MAX 2147483647#define INT_MIN (-INT_MAX -1)class Solution {public:原创 2015-10-20 08:35:54 · 898 阅读 · 1 评论 -
leetcode--31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2016-08-08 20:05:19 · 427 阅读 · 0 评论 -
leetcode--27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2016-08-08 15:29:19 · 355 阅读 · 0 评论 -
leetcode--26. Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-08-08 15:13:59 · 351 阅读 · 0 评论 -
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原创 2016-08-08 14:52:45 · 328 阅读 · 0 评论 -
排序算法--冒泡、插入、归并、快排
整理了一下几种常见的排序算法,包括冒泡、插入、归并、快排。还有另外几种待整理:堆排序、希尔排序、桶排序直接上代码:#include#include//#include using namespace std;void swap(int* a, int* b){ if(a==NULL || b==NULL) cout << "bad in swap" <<原创 2016-06-23 10:19:47 · 537 阅读 · 0 评论 -
二分查找递归和非递归实现
非递归实现:int BinSearch(int data[], int length, int key){ if ( data == NULL || length <= 0) throw new std::exception("Invalid Parameters"); int start = 0; int end = length - 1; int mid = start;原创 2016-06-21 22:44:20 · 413 阅读 · 0 评论 -
红黑树(RB-tree)比AVL树的优势在哪?
今天看了STL源码剖析中关于红黑树的原理和实现,看完复杂的节点插入、节点颜色变换后不禁想:这些功能经典的AVL树也能实现,为什么要提出红黑树?查了些资料,并且加上自己理解,感叹红黑树的巧妙。首先红黑树是不符合AVL树的平衡条件的,即每个节点的左子树和右子树的高度最多差1的二叉查找树。但是提出了为节点增加颜色,红黑是用非严格的平衡来换取增删节点时候旋转次数的降低,任何不平衡都会在三次旋转之内解决原创 2016-06-16 17:03:24 · 49315 阅读 · 6 评论 -
二叉搜索树与双向链表
要求:输入棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的节点,只能调整树种结点指针的指向。具体见剑指offer题27。 分析:在二叉树中,每个节点都有两个指向子节点的指针。而在双向链表中,每一个节点也有两个指针,分别指向向前和后向的节点。因此这两种数据结构有相似之处,并且二叉搜索树是一种排序的数据结构,可以转换为排序的双向链表。主要思想:将原先指向左子节点的原创 2016-04-28 12:20:18 · 611 阅读 · 0 评论 -
leetcode--34. 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原创 2016-08-08 21:36:54 · 466 阅读 · 0 评论