![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
lyh_xd
一匹正在努力提高算法、编程水平的机器学习马
展开
-
线索二叉树
线索二叉树的原理 通过考察各种二叉链表,不管二叉树的形态如何,空链域的个数总是多过非空链域的个数。准确的说,n 个结点的二叉链表共有 2n 个链域,非空链域为 n-1,但其中的空链域却有 n+1 个。原创 2016-04-12 21:35:31 · 608 阅读 · 0 评论 -
leetcode 110. Balanced Binary Tree
判断一个二叉树是否是 height-balaced 的二叉树,height-balaced 二叉树的定义是:任一结点的左右子树高度差不超过1.原创 2016-04-13 00:13:24 · 253 阅读 · 0 评论 -
Leetcode 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in plac原创 2016-06-17 22:15:30 · 229 阅读 · 0 评论 -
Leetcode 337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour,原创 2016-06-17 10:28:59 · 233 阅读 · 0 评论 -
字符串匹配的Boyer-Moore算法
转载自:http://www.ruanyifeng.com/blog/2013/05/boyer-moore_string_search_algorithm.html上一篇文章,我介绍了KMP算法。 但是,它并不是效率最高的算法,实际采用并不多。各种文本编辑器的”查找”功能(Ctrl+F),大多采用Boyer-Moore算法。Boyer-Moore算法不仅效率高,而且构思巧妙,容易理解。1977年转载 2016-06-12 23:54:52 · 287 阅读 · 0 评论 -
字符串匹配的KMP算法
本篇关于KMP算法的讲解是我搜集到的认为讲的最简单易懂的一篇,分享给大家一起学习。转载自:http://www.ruanyifeng.com/blog/2013/05/boyer-moore_string_search_algorithm.html 字符串匹配是计算机的基本任务之一。 举例来说,有一个字符串”BBC ABCDAB ABCDABCDABDE”,我想知道,里面是否包含另一个字符串”ABC转载 2016-06-12 23:36:50 · 258 阅读 · 0 评论 -
Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two原创 2016-05-26 16:11:00 · 240 阅读 · 0 评论 -
Leetcode 378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not the原创 2016-08-02 14:58:48 · 354 阅读 · 0 评论 -
Leetcode 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.最开始写了下面这个错误原创 2016-06-16 21:59:18 · 315 阅读 · 0 评论 -
Leetcode 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of unique ele原创 2016-06-15 20:51:40 · 333 阅读 · 0 评论 -
Leetcode 28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.这道题目主要有这三种方法。在Leetcode上并没有展现KMP和BM算法的优势,应该与OJ的测试样例有关; 暴力解法时间复杂度 O(MN), KMP 为原创 2016-06-13 18:13:39 · 281 阅读 · 0 评论 -
猴子选大王
问题描述:n 只猴子要选大王,选举办法如下:所有猴子按1,2……n 编号围成一圈,从第一号开始顺序 1,2……m, 凡是报 m 号的退出圈外,如此循环报数直到圈内只剩一只猴子时这只猴子就是大王。思路:利用单向循环链表模拟此过程,输出选出的大王编号。原创 2016-04-26 21:00:13 · 425 阅读 · 0 评论 -
最小生成树之Prim算法理解
MST(Minimum Spanning Tree,最小生成树)问题有两种通用的解法,Prim算法就是其中之一,它是从点的方面考虑构建一颗MST,大致思想是:设图G顶点集合为U,首先任意选择图G中的一点作为起始点a,将该点加入集合V,再从集合U-V中找到另一点b使得点b到V中任意一点的权值最小,此时将b点也加入集合V;以此类推,现在的集合V={a,b},再从集合U-V中找到另一点c使得点c到V中任意一点的权值最小,转载 2016-04-12 22:01:53 · 293 阅读 · 0 评论 -
Leetcode 226. Invert Binary Tree
Invert a binary tree. 题目意思是将二叉树每层的左右孩子交换。原创 2016-05-24 14:30:42 · 230 阅读 · 0 评论