![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法和数据结构
WittyCollegeStudent
这个作者很懒,什么都没留下…
展开
-
HashMap实现原理分析
1. HashMap的数据结构数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端。 数组数组存储区间是连续的,占用内存严重,故空间复杂的很大。但数组的二分查找时间复杂度小,为O(1);数组的特点是:寻址容易,插入和删除困难;链表链表存储区间离散,占用内存比较宽松,故空间复杂度很小,但时间复杂度很大,达O(N)。链表的特点是:寻址困难,插入和删除容易。哈希表那么转载 2017-03-19 13:53:00 · 334 阅读 · 0 评论 -
删除排序二叉树的节点
原题(LeetCode)Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basically, the deletion can be di原创 2017-03-12 19:38:14 · 822 阅读 · 0 评论 -
字符串反转
LeetCode原题:Reverse String IIDescription: Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less th原创 2017-03-12 21:43:10 · 748 阅读 · 0 评论 -
求下一个更大的数
LeetCode原题:Next Greater Element IIDescription:Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next原创 2017-03-13 21:31:00 · 923 阅读 · 0 评论 -
求海岛周长
LeetCode原题:Description:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). T原创 2017-03-14 00:12:07 · 693 阅读 · 1 评论 -
平板上的战舰
LeetCode原题:Battleships in a BoardDescription:Given an 2D board, count how many battleships are in it. The battleships are represented with ‘X’s, empty slots are represented with ‘.’s. You may assume th原创 2017-03-15 21:06:33 · 428 阅读 · 0 评论 -
重建二叉树
简介重建二叉树指的是在给出二叉树节点的几种遍历顺序的条件下,让求出其原二叉树的结构。其实只要已知其中序遍历和另一种遍历,就足以重建二叉树了。重建方法比如给出某二叉树的前序遍历{1,2,4,7,3,5,6,8}和其中序遍历{4,7,2,1,5,3,8,6},那么,我们可以很明显的知道此二叉树的根结点是1,又由中序遍历知道{4,7,2}是此二叉树的左子树,对应的前序遍历是{2,4,7},而原二叉树的右子原创 2017-03-31 21:15:17 · 313 阅读 · 0 评论 -
优雅的点
编者最近遇到这样一道编程题:问题描述:小易有一个圆心在坐标原点的圆,小易知道圆的半径的平方。小易认为在圆上的点而且横纵坐标都是整数的点是优雅的,小易现在想寻找一个算法计算出优雅的点的个数,请你来帮帮他。 例如:半径的平方如果为25 优雅的点就有:(+/-3, +/-4), (+/-4, +/-3), (0, +/-5) (+/-5, 0),一共12个点。 输入描述: 输入为一个整数,即为圆原创 2017-03-23 16:20:02 · 591 阅读 · 0 评论 -
排序——选择排序
简介选择排序是一种常用的排序方法,其排序思想是这样的:对于数组n,第一趟排序取出n个元素中最小的元素,第二趟排序取出剩余n-1个元素中最小的元素……直到整个数组取完为止。常用的选择排序有简单选择排序、树形选择排序和堆排序。注意:选择排序是一种不稳定的排序算法一、简单选择排序简单选择排序是一种比较好理解的选择排序,其实现思想也非常简单:对于数组n,第一趟排序找出n个元素中最小的元素与第1个元素交换,第原创 2017-03-29 13:15:08 · 449 阅读 · 0 评论 -
排序——交换排序
简介交换排序是一种通过不断比较数组中两个元素的大小,如果大小顺序与要得到的排序相反,则交换位置,否则不交换的排序方法。常用的交换排序法就是冒泡排序和快速排序。一、交换排序假设有n个元素,则第一趟排序中,依次比较下标为0与1、1与2、2与3……n-1与n的大小,并且每次比较中,如果与目标顺序不同,则交换两个数的大小。第二趟排序中,依次比较下标为0与1、1与2、2与3……n-2与n-1的大小……一共n-原创 2017-03-28 23:17:24 · 627 阅读 · 0 评论 -
排序——插入排序
编者最近在复习排序算法,这里记录一下自己的一些体会。简介这里介绍的直接插入排序法是最原始的一种直接插入排序。从第2个元素开始扫描输入数组,即从第2个元素开始向前面的数组中插入。这样,每一次插入时,前面的数组都能够保证有序。举个例子例如对数组[256, 0 , 3 , 9 , 11, 7]。 第一次排序是将下标为1的元素0插入前面的数组[256]中,得到第一次排序后的数组为[0, 256 , 3 ,原创 2017-03-27 22:56:37 · 465 阅读 · 0 评论 -
求出现频率最高的子树值
Most Frequent Subtree SumDescription:Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the原创 2017-03-16 13:51:01 · 613 阅读 · 0 评论 -
找出数组中的重复元素
Find All Duplicates in an Array Add to ListDescriptionGiven an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear t原创 2017-03-16 20:42:01 · 663 阅读 · 0 评论 -
求最长上升子序列
最长上升子序列原创 2017-04-22 12:44:55 · 370 阅读 · 0 评论