摘要:
题目描述: 在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。 思路分析:这道题第一次看到类似的题是在算法设计与分析这本书的第三章分治策略,当时书上给的方法是以中位数为基准进行第K小元素的查找,还记得若采取这样的方法,则算法的 阅读全文
摘要:
最近正好数据结构上到二叉树,顺便把二叉树的算法给巩固了下,来到leetcode正好看到每日一题出的是二叉树的LCA问题,花了点时间完成。 首先是一颗树的LCA的定义:对于有根树 T 的两个结点 p、q,最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x 的深度尽可能大(一个节点也可以 阅读全文
摘要:
A character string is said to have period k if it can be formed by concatenating one or more repetitions of another string of length k. For example, t 阅读全文
摘要:
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N (1 阅读全文