Weekly Contest 111-------->942. DI String Match
Given a string S that only contains "I" (increase) or "D" (decrease), let N = S.length.
Return any permutation A of [0, 1, ..., N] such that for all i = 0, ..., N-1:
- If
S[i] == "I", thenA[i] < A[i+1] - If
S[i] == "D", thenA[i] > A[i+1]
Example 1:
Input: "IDID"
Output: [0,4,1,3,2]
Example 2:
Input: "III"
Output: [0,1,2,3]
Example 3:
Input: "DDI"
Output: [3,2,0,1]
Note:
1 <= S.length <= 10000Sonly contains characters"I"or"D".
Approach #1:
class Solution {
public:
vector<int> diStringMatch(string S) {
int len = S.length();
vector<int> ans(len+1, 0);
int index = 0;
for (int i = 0; i < len; ++i)
if (S[i] == 'I') ans[i] = index++;
ans[len] = index++;
for (int i = len-1; i >= 0; --i)
if (S[i] == 'D') ans[i] = index++;
return ans;
}
};
Weekly Contest 111-------->942. DI String Match的更多相关文章
- 【Leetcode_easy】942. DI String Match
problem 942. DI String Match 参考 1. Leetcode_easy_942. DI String Match; 完
- #Leetcode# 942. DI String Match
https://leetcode.com/problems/di-string-match/ Given a string S that only contains "I" (in ...
- LeetCode 942 DI String Match 解题报告
题目要求 Given a string S that only contains "I" (increase) or "D" (decrease), let N ...
- 【leetcode】942. DI String Match
题目如下: Given a string S that only contains "I" (increase) or "D" (decrease), let ...
- 【LeetCode】942. DI String Match 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 942. 增减字符串匹配(DI String Match) 49
942. 增减字符串匹配 942. DI String Match 题目描述 每日一算法2019/6/21Day 49LeetCode942. DI String Match Java 实现 and ...
- LeetCode.942-DI字符串匹配(DI String Match)
这是悦乐书的第361次更新,第388篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第223题(顺位题号是942).给定仅包含I(增加)或D(减少)的字符串S,令N = S ...
- [Swift]LeetCode942. 增减字符串匹配 | DI String Match
Given a string S that only contains "I" (increase) or "D" (decrease), let N = S. ...
- Leetcode942. DI String Match增减字符串
给定只含 "I"(增大)或 "D"(减小)的字符串 S ,令 N = S.length. 返回 [0, 1, ..., N] 的任意排列 A 使得对于所有 i ...
随机推荐
- Android中通过GPS或NetWork获取当前位置的经纬度
今天在Android项目中要实现一个通过GPS或NetWork来获取当前移动终端设备的经纬度功能.要实现该功能要用到Android Framework 中的 LocationManager 类.下面我 ...
- Mvc创建并注册防盗链
创建CustomHandler.JpgHandler public class JpgHandler : IHttpHandler { public void ProcessRequest(HttpC ...
- 相似进程死掉Process com.midea.mmp2 died.
此异常查到网上有一篇不错的文章例如以下: 08:56:03,273 INFO – 运行Do func=[GetSeqNo] keyNam=[keynam];KeyVal=[PRYPAYBILSYSTR ...
- 前端基础——CSS盒子模型
如今很多网页都是由很多个"盒子"拼接.嵌套而成,所以多少接触过网页设计的朋友一定都对CSS盒子模型有所了解. 为了更好的说明,先举个通俗的样例:在一个仓库中放了10个纸箱,每一个纸 ...
- DuiLib笔记之设置文本字体
设置文本字体要用到Font 它的常用属性如下 id 用于标识Font,类型:INT name 用于指定字体名称,类型:STRING size 用于指定字体大小,类型:INT bold 用于指定是否加粗 ...
- Delphi的类方法不是静态方法
Delphi中,类方法不是你理解的静态方法 Delphi中的类方法与C++类中的static方法完全没有可比性.Delphi中的类方法是有Self的,而Self就是类本身(注意不是对象),而这个Sel ...
- js 单例模式的实现方式----闭包和构造函数内部判断
闭包: var singleton = function( fn ){ var result; return function(){ return result || ( result = fn .a ...
- 前端面试常考知识点---CSS
前端面试常考知识点---js 1.CSS3的新特性有哪些 点我查看 CSS3选择器 . CSS3边框与圆角 CSS3圆角border-radius:属性值由两个参数值构成: value1 / valu ...
- Ubuntu 14.04 下 android studio 安装 和 配置【转】
本文转载自:http://blog.csdn.net/xueshanfeihu0/article/details/52979717 Ubuntu 14.04 下 android studio 安装 和 ...
- win7下使用source insight,没有Courier字体
http://hi.baidu.com/raoxj/item/0e3a3a3b2461c5be134b14fa 1. “控制面板:--->“字体”--->找到Courier New(建议用 ...