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 ...
随机推荐
- 【转】 IntelliJ IDEA 详细图解最常用的配置 ,适合刚刚用的新人
本文转载于:https://blog.csdn.net/qq_27093465/article/details/52918873 刚刚使用IntelliJ IDEA 编辑器的时候,会有很多设置,会方便 ...
- python实现测试中常用的脚本(待完善)
一. Python操作MySQL数据库,简单的增删改查 # coding=utf-8 ''' Created on 2015年5月12日 @author: Administrator ''' impo ...
- 分析Memcached客户端如何把缓存数据分布到多个服务器上
Memcached客户端可以设多个memcached服务器,它是如何把数据分发到各个服务器上,而使各个服务器负载平衡的呢? 可以看看.net版中的客户端中的源码,就可以知道 先看代码: 1 /// ...
- 最实用windows 下python+numpy安装(转载)
最实用windows 下python+numpy安装 如题,今天兜兜转转找了很多网站帖子,一个个环节击破,最后装好费了不少时间. 希望这个帖子能帮助有需要的人,教你一篇帖子搞定python+numpy ...
- C分配struct变量一个不理解的地方
- Android 你可能忽略的提高敲代码效率的方式 (转)
每日推荐 Eyepetizer-in-Kotlin:一款简约的小视频app,带你走进kotlin 作为学习kotlin的一款app,在撸代码的过程中学习kotlin的语法及特性. Eyepetizer ...
- cnn 实例
http://www.geekcome.com/content-10-3761-1.html http://www.geekcome.com/content-10-3761-1.html http:/ ...
- PHPstudy如何在本地搭建多站点
参考地址: http://jingyan.baidu.com/article/e52e36154227ef40c70c5147.html
- Domino Angular 前端UI开发
因为如今前端的要求越来越专业化,不少企业已经有前端的专业职位了.当然我们dominio软件企业.有些也在特意招一些前端的project师. 比方如今流程的多平台(之前我的有教程).就必需要有专业的UI ...
- TP框架---thinkphp表单验证
自动验证是ThinkPHP模型层提供的一种数据验证方法,可以在使用create创建数据对象的时候自动进行数据验证.验证的代码要写在模型层即Model里面. 数据验证有两种方式: 静态方式:在模型类里面 ...