Reverse Subarray To Maximize Array Value
2020-02-03 20:43:46
问题描述:

问题求解:
public boolean canTransform(String start, String end) {
int n = start.length();
List<int[]> s = new ArrayList<>();
List<int[]> e = new ArrayList<>();
for (int i = 0; i < n; i++) {
char c = start.charAt(i);
if (c == 'L' || c == 'R') {
s.add(new int[]{c - 'a', i});
}
c = end.charAt(i);
if (c == 'L' || c == 'R') {
e.add(new int[]{c - 'a', i});
}
}
if (s.size() != e.size()) return false;
for (int i = 0; i < s.size(); i++) {
int[] cs = s.get(i);
int[] ce = e.get(i);
if (cs[0] != ce[0]) return false;
if (cs[0] == 'L' - 'a' && cs[1] < ce[1]) return false;
if (cs[0] == 'R' - 'a' && cs[1] > ce[1]) return false;
}
return true;
}
Reverse Subarray To Maximize Array Value的更多相关文章
- 数学-绝对值-Reverse Subarray To Maximize Array Value
2020-02-11 12:01:21 问题描述: 问题求解: 本题的难度个人感觉还是蛮大的,主要是不容易想到O(n)的解. 对于 ...a, [b, ... , c], d, ...,如果我们将其中 ...
- Get the largest sum of contiguous subarray in an int array
When I finished reading this problem,I thought I could solve it by scanning every single subarray in ...
- [array] leetcode - 53. Maximum Subarray - Easy
leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...
- 152. Maximum Product Subarray (Array; DP)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 53. Maximum Subarray (Array; DP)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- array题目合集
414. Third Maximum Number 给一个非空的整数数组,找到这个数组中第三大的值,如果不存在,那么返回最大的值.要求时间复杂度为o(n) 例如: Example 1: Input: ...
- CodeForces-1155D Beautiful Array
Description You are given an array \(a\) consisting of \(n\) integers. Beauty of array is the maximu ...
- Educational Codeforces Round 63 D. Beautiful Array
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...
随机推荐
- Python学习笔记--装饰器的实验
装饰器既然可以增加原来函数的功能,那能不能改变传给原函数的参数呢? 我们实验一下,先上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date ...
- 死磕Lambda表达式(二):Lambda的使用
城市就是森林,每一个男人都是猎手,每一个女人都是陷阱.--<三体> 在哪使用Lambda表达式? 在上一篇文章(传送门)中介绍了Lambda表达式的基本语法,其中的举了一个Lambda表达 ...
- ts文件的编译和运行
hello.ts代码 function sayHello(person: string): string { return 'Hello, ' + person; } let user = 'Tom' ...
- 06 EntityManager和EntityTransaction
EntityManager 在 JPA 规范中, EntityManager是完成持久化操作的核心对象.实体类作为普通 java对象,只有在调用 EntityManager将其持久化后才会变成持久化对 ...
- 【03】openlayers 地图事件
绑定事件:map.on(type, listener) 取消绑定:map.un(type, listener) type:事件类型 listener:执行得函数体 事件类型: //事件类型 let t ...
- ES6中的Promise使用总结
One.什么是Promise? Promise是异步编程的解决方案,而它本身也就是一个构造函数,比传统的异步解决[回调函数]和[事件]更合理,更强大. Two.Promise有何作用? 作用:解决回调 ...
- Flutter json 2 model with Built Value
Flutter json 2 model with Built Value Flutter中json转换model, 除了手动转之外, 就是利用第三方库做一些代码生成. 流行的库有: json_ser ...
- [android]p7-1 fragment学习笔记
本文源自<android权威编程指南第3版>第7章UI fragment与fragment 第7章主要内容是实现一个记录不良行为的APP(部分实现),有列表,有具体的行为内容显示.第7章主 ...
- Django_orm
Object Relational Mapping(ORM) ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据 ...
- linux ftp服务器设置,只允许用户访问指定的文件夹,禁止访问其他文件夹
在Linux中添加ftp用户,并设置相应的权限,操作步骤如下: 1.环境:ftp为vsftp.被限制用户名为test.被限制路径为/home/test 2.建用户:在root用户下: useradd ...