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. js笔记-0

    #js笔记-0 数组: indexOf方法: Array也可以通过indexOf()来搜索一个指定的元素的位置: var arr = [10, 20, '30', 'xyz']; arr.indexO ...

  2. web博客

    欢迎大家来戳一戳

  3. 嗨! Apriori算法

    Association Rule 一:项集和规则 1.1 认识名词: Association Rule : 关联规则 Frequent Itemsets : 频繁项集 Sequential Patte ...

  4. 这些Zepto中实用的方法集

    前言 时间过得可真快,转眼间2017年已去大半有余,你就说吓不吓人,这一年你成长了多少,是否荒度了很多时光,亦或者天天向上,收获满满.今天主要写一些看Zepto基础模块时,比较实用的部分内部方法,在我 ...

  5. js事件的三个阶段

    js事件的三个阶段分别为:捕获.目标.冒泡 1.捕获:事件由页面元素接收,逐级向下,到具体的元素 2.目标:具体的元素本身 3.冒泡:跟捕获相反,具体元素本身,逐级向上,到页面元素 IE5.5:div ...

  6. Subsequence POJ - 3061

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22040   Accepted: 9404 Desc ...

  7. 微信小程序结构目录、配置介绍、视图层(数据绑定,运算,列表渲染,条件渲染)

    目录 一.小程序结构目录 1.1 小程序文件结构和传统web对比 1.2 基本的项目目录 二.配置介绍 2.1 配置介绍 2.2 全局配置app.json 2.3 page.json 三.视图层 3. ...

  8. spring boot 过滤器 前后端分离跨域sessionId不一致

      import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http ...

  9. ES6的编程风格

    1,建议使用let替代var 2,全局常量使用const,多使用const有利于提高程序的运行效率. const有两个好处:一是阅读代码的人立刻会意识到不应该修改这个值,二是防止无意间修改变量值导致错 ...

  10. AX中Json转化成表记录

    static void JsonToTable(str _json,Common _Common){    sysdictTable        dictTable;    TableId      ...