Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 思路:既然数组里的元素已经按升序排好序了,那么不难想到用二分法来做这道题。 /** * Definiti ...
分类:
其他好文 时间:
2017-10-29 14:36:54
阅读次数:
99
题解:前缀和思想(菜菜菜,我为什么这么菜,太菜 了,不能忍不能忍,菜菜菜) 这和前缀和,你把他理解成折线图(就和股票一样),然后容易发现相等的地方就是答案(训练是画了折线图也没看出来,菜菜菜,太菜了)。然后遍历一下就行了 代码: ...
分类:
其他好文 时间:
2017-10-24 22:57:44
阅读次数:
150
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 题目含义:给定一个升序的列表,够着一个平衡二叉树 ...
分类:
其他好文 时间:
2017-10-24 14:51:01
阅读次数:
138
https://www.luogu.org/problem/show?pid=1360 题目描述 Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow d ...
分类:
其他好文 时间:
2017-10-22 23:30:07
阅读次数:
255
题目背景 题目描述: 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连续的牛来进行比赛. 但是为了避免水平悬殊,牛的身高不应该相差太大. John 准备了Q (1 <= Q <= 1 ...
分类:
其他好文 时间:
2017-10-22 22:22:00
阅读次数:
92
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the dept ...
分类:
其他好文 时间:
2017-10-22 00:15:49
阅读次数:
175
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题目含义:给定了一个升序的数组,转换成一个平衡二叉树 ...
分类:
其他好文 时间:
2017-10-21 19:19:54
阅读次数:
246
题目链接:http://codeforces.com/problemset/problem/873/B 题目大意:一个字符串全部由‘0’和‘1’组成,当一段区间[l,r]内的‘0’和‘1’个数相等,则称为平衡子串,求最长的平衡子串。 解题思路:将0换成-1,算出每个点的前缀和,若两个点前缀和相同,从 ...
分类:
其他好文 时间:
2017-10-19 00:52:36
阅读次数:
136
Description You are given a string s consisting only of characters 0 and 1. A substring [l,?r] of s is a string slsl?+?1sl?+?2... sr, and its length e ...
分类:
其他好文 时间:
2017-10-15 21:19:35
阅读次数:
182
原题链接:Balanced Substring 题意:给出一个n长度的01串,其中含有相同0,1个数的子串被称为“平衡串”,问最长的平衡串的长度。 思路:官方题解里讲的比较清楚,我这里就翻译一下。 我们可以先对0,1的个数求前缀和,记为sum0[i], sum1[i],表示前i个字符中0、1分别有多 ...
分类:
其他好文 时间:
2017-10-15 19:36:11
阅读次数:
162