自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 67. Binary Tree Inorder Traversal-二叉树的中序遍历(递归与非递归法)

Description给出一棵二叉树,返回其中序遍历样例给出二叉树 {1,#,2,3}, 1 \ 2 / 3返回 [1,3,2].挑战 你能使用非递归算法来实现么?Solution算法思路:遍历法(递归)分治法(递归)非递归法实现中序遍历的通用版本(非递归)    利用 stack 进行 Binary Tree Iterator。stack 中保存一路走到当前节...

2018-04-21 21:56:30 562

原创 86. Binary Search Tree Iterator-二叉查找树迭代器(非递归的二叉树中序遍历)

Description设计实现一个带有下列属性的二叉查找树的迭代器:元素按照递增的顺序被访问(比如中序遍历)next()和hasNext()的询问操作要求均摊时间复杂度是O(1)样例对于下列二叉查找树,使用迭代器进行中序遍历的结果为 [1, 6, 10, 11, 12] 10 / \1 11 \ \ 6 12挑战 额外空间复杂度是O(h),其...

2018-04-21 21:20:53 935

原创 900. Closest Binary Search Tree Value

DescriptionGiven a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. 注意事项Given target value is a floating point.You are guaranteed to have only ...

2018-04-19 17:10:43 364

原创 130. Heapify-堆化(siftup & siftdown版本)

Description给出一个整数数组,堆化操作就是把它变成一个最小堆数组。对于堆数组A,A[0]是堆的根,并对于每个A[i],A [i * 2 + 1]是A[i]的左儿子并且A[i * 2 + 2]是A[i]的右儿子。说明什么是堆?堆是一种数据结构,它通常有三种方法:push, pop 和 top。其中,“push”添加新的元素进入堆,“pop”删除堆中最小/最大元素,“top”返回堆中最小/最...

2018-04-14 23:21:17 6200 1

原创 615. Course Schedule-课程表(拓扑排序)

Description现在你总共有 n 门课需要选,记为 0 到 n - 1.一些课程在修之前需要先修另外的一些课程,比如要学习课程 0 你需要先学习课程 1 ,表示为[0,1]给定n门课以及他们的先决条件,判断是否可能完成所有课程?样例给定 n = 2,先决条件为 [[1,0]] 返回 true给定 n = 2,先决条件为 [[1,0],[0,1]] 返回 falseSolution算法思路:已...

2018-04-10 10:01:40 1385

原创 433. Number of Islands-岛屿的个数

Description给一个01矩阵,求不同的岛屿的个数。0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛。我们只考虑上下左右为相邻。样例在矩阵:[ [1, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 0, 0, 1, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]中有 3 个岛.Solution算法思路:1....

2018-04-07 11:43:42 541

原创 7. Binary Tree Serialization-二叉树的序列化和反序列化(BFS)

Description设计一个算法,并编写代码来序列化和反序列化二叉树。将树写入一个文件被称为“序列化”,读取文件后重建同样的二叉树被称为“反序列化”。如何反序列化或序列化二叉树是没有限制的,你只需要确保可以将二叉树序列化为一个字符串,并且可以将字符串反序列化为原来的树结构。 注意事项There is no limit of how you deserialize or serialize a b...

2018-04-05 12:25:38 599

原创 814. Shortest Path in Undirected Graph-无向图最短路径(双向宽度优先搜索算法)

DescriptionGive an undirected graph, in which each edge's length is 1, and give two nodes from the graph. We need to find the length of the shortest path between the given twonodes.样例Given graph = {1,...

2018-04-04 21:34:38 793

原创 143. Sort Colors II - 排颜色 II(rainbowSort彩虹排序)

Description给定一个有n个对象(包括k种不同的颜色,并按照1到k进行编号)的数组,将对象进行分类使相同颜色的对象相邻,并按照1,2,...k的顺序进行排序。 注意事项You are not suppose to use the library's sort function for this problem.k <= n样例给出colors=[3, 2, 2, 1, 4],k=4,...

2018-04-02 20:50:52 5771 1

原创 382. Triangle Count-三角形计数

Description给定一个整数数组,在该数组中,寻找三个数,分别代表三角形三条边的长度,问,可以寻找到多少组这样的三个数来组成三角形?Given an array of integers, how many three numbers can be found in the array, so that we can build an triangle whose three edges le...

2018-03-30 23:02:42 478

原创 57. 3Sum-三数之和

Description给出一个有n个整数的数组S,在S中找到三个整数a, b, c,找到所有使得a + b + c = 0的三元组。 注意事项在三元组(a, b, c),要求a <= b <= c。结果不能包含重复的三元组。Given an array S of n integers, are there elements a, b, c in S such that a + b + ...

2018-03-30 21:46:22 298

原创 120. Word Ladde——单词接龙(BFS分层遍历)

Description给出两个单词(start和end)和一个字典,找到从start到end的最短转换序列比如:每次只能改变一个字母。变换过程中的中间单词必须在字典中出现。 注意事项如果没有转换序列则返回0。所有单词具有相同的长度。所有单词都只包含小写字母。Given two words (start and end), and a dictionary, find the length of s...

2018-03-29 16:21:18 1128

原创 127. Topological Sorting——拓扑排序(BFS)

DescriptionGiven an directed graph, a topological order of the graph nodes is defined as follow:For each directed edge A -> B in graph, A must before B in the order list.The first node in the order...

2018-03-29 08:48:56 1069

原创 137. Clone Graph——克隆图(BFS宽度优先搜索)

Description克隆一张无向图,图中的每个节点包含一个 label 和一个列表 neighbors。数据中如何表示一个无向图?http://www.lintcode.com/help/graph/你的程序需要返回一个经过深度拷贝的新图。这个新图和原图具有同样的结构,并且对新图的任何改动不会对原图造成任何影响。样例比如,序列化图 {0,1,2#1,2#2,2} 共有三个节点, 因此包含两个个分...

2018-03-29 07:51:30 370

原创 200. Longest Palindromic Substring-最长回文子串

Description给出一个字符串(假设长度最长为1000),求出它的最长回文子串,你可以假定只有一个满足条件的最长回文串。样例给出字符串 "abcdzdcab",它的最长回文子串为 "cdzdc"。挑战 O(n2) 时间复杂度的算法是可以接受的,如果你能用 O(n) 的算法那自然更好。Solution这道题一共有五种解法:Manacher's Algorithm - O(n)      ---...

2018-03-18 17:11:57 756

原创 69. Binary Tree Level Order Traversal - 二叉树的层次遍历

DescriptionGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).ExampleGiven binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 / \...

2018-03-14 18:03:56 326 1

原创 464. Sort Integers II (Quick Sort & Merge Sort)

DescriptionGiven an integer array, sort it in ascending order. Use quick sort, merge sort, heap sort or any O(nlogn) algorithm.ExampleGiven [3, 2, 1, 4, 5], return [1, 2, 3, 4, 5].Tags Quick Sort Sort...

2018-03-07 08:41:07 284

原创 437. Copy Books

DescriptionGiven n books and the ith book has A[i] pages. You are given k people to copy the n books.n books list in a row and each person can claim a continous range of the n books. For example one c...

2018-03-01 19:26:52 631

原创 75. Find Peak Element(二分法)

LintCodeDescriptionThere is an integer array which has the following features:The numbers in adjacent positions are different.A[0] < A[1] && A[A.length - 2] > A[A.length - 1].We define a...

2018-02-28 10:33:38 400

原创 159. Find Minimum in Rotated Sorted Array(二分法)

DescriptionSuppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element. NoticeYou may assume no duplicate exists...

2018-02-27 23:00:19 207

原创 在大数组中查找 · Search in a Big Sorted Array(二分法)

Description给一个按照升序排序的正整数数组。这个数组很大以至于你只能通过固定的接口 ArrayReader.get(k) 来访问第k个数。(或者C++里是ArrayReader->get(k)),并且你也没有办法得知这个数组有多大。找到给出的整数target第一次出现的位置。你的算法需要在O(logk)的时间复杂度内完成,k为target第一次出现的位置的下标。如果找不到targe...

2018-02-27 22:15:07 1116

原创 74. First Bad Version(二分法)

DescriptionThe code base version is an integer start from 1 to n. One day, someone committed a bad version in the code case, so it caused this version and the following versions are all failed in the ...

2018-02-27 19:19:15 133

原创 457. Classical Binary Search 模板解法

DescriptionFind any position of a target number in a sorted array. Return -1 if target does not exist.ExampleGiven [1, 2, 2, 4, 5, 5].For target = 2, return 1 or 2.For target = 5, return 4 or 5.For ta...

2018-02-26 23:34:42 294

原创 13. strStr

Description对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回 -1。Clarification在面试中我是否需要实现KMP算法?不需要,当这种问题出现在面试中时,面试官很可能只是想要测试一下你的基础应用能力。当然你需要先跟面试官确认清楚要怎么实现这个题。Exampl...

2018-02-26 20:11:57 90

原创 strStr II - Rabin Karp

DescriptionImplement strStr function in O(n + m) time.strStr return the first index of the target string in a source string. The length of the target string is m and the length of the source string is...

2018-02-23 00:14:15 239

原创 18. Subsets II

DescriptionGiven a list of numbers that may has duplicate numbers, return all possible subsets NoticeEach element in a subset must be in non-descending order.The ordering between two subsets is free.T...

2018-02-21 21:20:28 160

原创 17. Subsets

Given a set of distinct integers, return all possible subsets. NoticeElements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.ExampleIf S = [1,2,3], a s...

2018-02-21 00:08:36 186

转载 32位64位操作系统基本数据类型字节大小

32位64位操作系统基本数据类型字节大小

2017-05-05 16:02:25 800

原创 为什么不能越界访问malloc分配的内存

之前在遇到了使用`malloc()`分配内存后,如果发生内存指针越界,则会导致下次使用`malloc()`分配内存失败的后果。但是,上次的`malloc()`函数调用,为何会影响到下次呢?这就要从`malloc()`的实现原理说起了。

2017-04-14 17:37:50 2973

原创 malloc函数分配内存失败的原因及解决方法

本文简单描述了malloc()函数分配内存失败的原因以及解决方法,对指针越界造成的分配内存失败做了详细探讨,对之后的内存管理及指针使用很有帮助。

2017-04-12 19:38:22 57347 11

转载 Keil调试局部变量显示"not in scope"的问题解决

Keil调试局部变量显示"not in scope"的问题解决    今天在调试程序的时候,发现函数返回值赋值给变量时,变量值总是显示"not in scope",无法看到变量被赋的值。    出现这种情况的原因是这个局部变量没被分配到内存,或者变量被编译器优化了。    编译器优化级别高的时候,编译器为了优化,可能并没有按照我们想要执行的代码汇编。

2017-04-10 10:22:21 2155 1

转载 再次理解STM32中的堆栈机制

STM32中的堆栈在启动文件中有初始设置,也可以根据需求调整大小,不同的类型的变量也会存储在内存的不同区域。因此,深入理解STM32中的堆栈机制,对于合理使用内存,以及更高效的内存管理至关重要。本文针对不同类型变量在内存中的存储位置,以及如何调整堆栈大小做了简单介绍。

2017-04-07 16:05:03 7690

原创 FreeRTOS中的堆栈设置”与“系统启动文件中堆栈”的关系

本文由之前系统堆空间分配所引发,简要分析了“FreeRTOS中的堆栈设置”与“系统启动文件中堆栈”的关系 ,并进行了初步测试。证明了二者在系统内存空间上互不影响的结论。

2017-04-07 15:53:32 5883 3

原创 STM32分配堆栈空间不足问题原因及解决方法

本文针对实践中STM32堆栈空间不足问题展开讨论。经过分析发现,如果动态内存分配需求过多时,需要手动调节堆空间。可以通过修改启动文件或在STM32CubeMX中也可对堆栈大小进行修改。并初步得出用户可以有使用的堆空间约占系统堆空间一半的结论。

2017-04-06 21:20:39 32768 11

转载 Keil中 Program Size: Code RO-data RW-data ZI-data 所代表的意思

在Keil中编译工程成功后,在下面的Bulid Ouput窗口中会输出下面这样一段信息:Program Size: Code=6320  RO-data=4864  RW-data=44  ZI-data=1636  代表的意思:Code :是程序中代码所占字节大小RO-data :程序中所定义的指令和常量大小 (个人理解 :Read Only)RW-data :程序中已初始化

2017-04-06 21:07:47 1165

空空如也

空空如也

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

TA关注的人

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