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的更多相关文章

  1. 数学-绝对值-Reverse Subarray To Maximize Array Value

    2020-02-11 12:01:21 问题描述: 问题求解: 本题的难度个人感觉还是蛮大的,主要是不容易想到O(n)的解. 对于 ...a, [b, ... , c], d, ...,如果我们将其中 ...

  2. 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 ...

  3. [array] leetcode - 53. Maximum Subarray - Easy

    leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...

  4. 152. Maximum Product Subarray (Array; DP)

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  5. 53. Maximum Subarray (Array; DP)

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  6. array题目合集

    414. Third Maximum Number 给一个非空的整数数组,找到这个数组中第三大的值,如果不存在,那么返回最大的值.要求时间复杂度为o(n) 例如: Example 1: Input: ...

  7. CodeForces-1155D Beautiful Array

    Description You are given an array \(a\) consisting of \(n\) integers. Beauty of array is the maximu ...

  8. Educational Codeforces Round 63 D. Beautiful Array

    D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. [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 ...

随机推荐

  1. Python学习笔记--装饰器的实验

    装饰器既然可以增加原来函数的功能,那能不能改变传给原函数的参数呢? 我们实验一下,先上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date ...

  2. 死磕Lambda表达式(二):Lambda的使用

    城市就是森林,每一个男人都是猎手,每一个女人都是陷阱.--<三体> 在哪使用Lambda表达式? 在上一篇文章(传送门)中介绍了Lambda表达式的基本语法,其中的举了一个Lambda表达 ...

  3. ts文件的编译和运行

    hello.ts代码 function sayHello(person: string): string { return 'Hello, ' + person; } let user = 'Tom' ...

  4. 06 EntityManager和EntityTransaction

    EntityManager 在 JPA 规范中, EntityManager是完成持久化操作的核心对象.实体类作为普通 java对象,只有在调用 EntityManager将其持久化后才会变成持久化对 ...

  5. 【03】openlayers 地图事件

    绑定事件:map.on(type, listener) 取消绑定:map.un(type, listener) type:事件类型 listener:执行得函数体 事件类型: //事件类型 let t ...

  6. ES6中的Promise使用总结

    One.什么是Promise? Promise是异步编程的解决方案,而它本身也就是一个构造函数,比传统的异步解决[回调函数]和[事件]更合理,更强大. Two.Promise有何作用? 作用:解决回调 ...

  7. Flutter json 2 model with Built Value

    Flutter json 2 model with Built Value Flutter中json转换model, 除了手动转之外, 就是利用第三方库做一些代码生成. 流行的库有: json_ser ...

  8. [android]p7-1 fragment学习笔记

    本文源自<android权威编程指南第3版>第7章UI fragment与fragment 第7章主要内容是实现一个记录不良行为的APP(部分实现),有列表,有具体的行为内容显示.第7章主 ...

  9. Django_orm

    Object Relational Mapping(ORM) ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据 ...

  10. linux ftp服务器设置,只允许用户访问指定的文件夹,禁止访问其他文件夹

    在Linux中添加ftp用户,并设置相应的权限,操作步骤如下: 1.环境:ftp为vsftp.被限制用户名为test.被限制路径为/home/test 2.建用户:在root用户下: useradd ...