Data Structure Array: Given an array arr[], find the maximum j – i such that arr[j] > arr[i]
http://www.geeksforgeeks.org/given-an-array-arr-find-the-maximum-j-i-such-that-arrj-arri/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; int maxindexdiff(int arr[], int n) {
vector<int> L(n), R(n);
L[] = arr[];
for (int i = ; i < n; i++) L[i] = min(L[i-], arr[i]);
R[n-] = arr[n-];
for (int i = n-; i >= ; i--) R[i] = max(R[i+], arr[i]);
int left, right, ans;
left = right = ;
ans = -;
while (left < n && right < n) {
if (L[left] < R[right]) {
ans = max(ans, right - left);
right++;
}
else left++;
}
return ans;
} int main() {
int arr[] = {, , , , , , , , , };
cout << maxindexdiff(arr, ) << endl;
return ;
}
Data Structure Array: Given an array arr[], find the maximum j – i such that arr[j] > arr[i]的更多相关文章
- Data Structure Array: Maximum circular subarray sum
http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...
- Data Structure Array: Find the minimum distance between two numbers
http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...
- Data Structure Array: Program for array rotation
http://www.geeksforgeeks.org/array-rotation/ O(n), O(1) #include <iostream> #include <vecto ...
- [Swift]LeetCode211. 添加与搜索单词 - 数据结构设计 | Add and Search Word - Data structure design
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [Algorithm] Trie data structure
For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...
- 面试总结之数据结构(Data Structure)
常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...
- [Algorithm] Heap data structure and heap sort algorithm
Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...
- [LeetCode] 170. Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- JS 中 Array.slice() 和 Array.splice()方法
slice slice()就是对应String的substring()版本,它截取Array的部分元素,然后返回一个新的Array: var arr = ['A', 'B', 'C', 'D', 'E ...
随机推荐
- 隔行换色table
<style type="text/css"> table { margin: 0 auto; width: 600px; } table { border: 1px ...
- C# 使用UUID生成各种模式方法
UUID简单说明 常见的方式.可以利用数据库也可以利用程序生成,一般来说全球唯一. 优点: 1)简单,代码方便. 2)生成ID性能非常好,基本不会有性能问题. 3)全球唯一,在遇见数据迁移,系统数据合 ...
- Delphi中定义了四种布尔类型:Boolean,ByteBool,WordBool和LongBool。后面三种布尔类型是为了与其他语言兼容而引入的
bool是LongBool类型. Delphi中定义了四种布尔类型:Boolean,ByteBool,WordBool和LongBool.后面三种布尔类型是为了与其他语言兼容而引入的,一般情况下建议使 ...
- js 温故而知新 webkitTransitionEnd 监听Transition动画结束事件
css3的过渡属性transition,在动画结束时,也存在结束的事件:webkitTransitionEnd; 注意:transition,也仅仅有这一个事件. http://www.runoob. ...
- Hibernate学习之一级缓存
© 版权声明:本文为博主原创文章,转载请注明出处 Hibernate缓存: - 缓存是为了降低应用程序对物理数据源访问的频次,从而提供应用程序的运行性能的一种策略 - Hibernate缓存是提升和优 ...
- web开发方法
request.getContextPath()是在开发Web项目时,经常用到的方法,其作用是获取当前的系统路径.
- 企业级Nginx服务基础到架构优化详解
1.隐藏nginx header版本号 2.更改源码隐藏软件名称 3.更改nginx默认用户及用户组 4.配置nginx worker进程个数 5.根据CPU核数进行nginx进程优化 6.nginx ...
- iOS UIView添加阴影
_bottomView.layer.masksToBounds = NO; _bottomView.backgroundColor = [UIColor whiteColor]; _bottomVie ...
- windows upd广播包无法发送到局域网解决方法
不能发送广播包的电脑和可以发送广播报的主机对比,发现不能发送广播报的主机上都有安装虚拟机,也有虚拟网卡,将所有的虚拟网卡关闭,然后再进行测试,都正常了,无论是Win7,Win10还是Xp. 禁用VMw ...
- php 微信开发之新增上传/获取下载临时素材
php 微信开发之新增上传/获取下载临时素材 代码 <?php define("AppID","");//你的id define("AppSec ...