leetcode821
vector<int> shortestToChar(string S, char C) {
vector<int> V;
const int N = ;
int AYC[N];
int countC = ;
for (int i = ; i < S.size(); i++)
{
if (S[i] == C)
{
AYC[countC] = i;
countC++;
}
}
for (int i = ; i < S.size(); i++)
{
int min = INT_MAX;
for (int j = ; j < countC; j++)
{
int dif = abs(i - AYC[j]);
if (dif < min)
{
min = dif;
}
}
V.push_back(min);
}
return V;
}
leetcode821的更多相关文章
- [Swift]LeetCode821. 字符的最短距离 | Shortest Distance to a Character
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- Leetcode821.Shortest Distance to a Character字符的最短距离
给定一个字符串 S 和一个字符 C.返回一个代表字符串 S 中每个字符到字符串 S 中的字符 C 的最短距离的数组. 示例 1: 输入: S = "loveleetcode", C ...
随机推荐
- forEach和map的区别
写法上没什么区别,只是返回值会不一样,map能够返回每一项,而forEach则返回undefined,以后要用哪个你知道了吧?map返回新的数组,可以进行后续更多的操作,例如: let arr = [ ...
- js 下获取子元素的方法
笔记核心: firstElementChild只会获取元素节点对象,从名称就可以看出来,firstChild则可以获取文本节点对象(当然也可以获取元素节点对象),比如空格和换行都被当做文本节点. js ...
- 前端之HTML补充
一.列表 (1).无序列表<ul> <body> <ul type="disc"> <li>属性一</li> <l ...
- HDU - 6185 :Covering(矩阵乘法&状态压缩)
Bob's school has a big playground, boys and girls always play games here after school. To protect bo ...
- 高级C/C++编译技术之读书笔记(五)之动态库版本控制
最近有幸阅读了<高级C/C++编译技术>深受启发,该书深入浅出地讲解了构建过程(编译.链接)中的各种细节,从多个角度展示了程序与库文件或代码的集成方法,提出了面向代码复用和系统集成的软件架 ...
- LeetCode Next Closest Time
原题链接在这里:https://leetcode.com/problems/next-closest-time/description/ 题目: Given a time represented in ...
- fn project 对象模型
Applications At the root of everything are applications. In fn, an application is essentially a grou ...
- js插件大全 jquery插件大全
CocoaUI - 一个强大的 iOS UI 框架 http://www.cocoaui.com/ tab,slider,轮播不错的说 http://www.superslide2.com/index ...
- compoer 全局和单个项目切换源 composer update killed
演示地址: https://blog.csdn.net/hpugym/article/details/72588393 composer update killed https://cloud.ten ...
- Linux常用命令(个人使用频率较高)
1,日志查看 tail(cat) -f|grep ERROR(任意字符) filepath (任意行数) -f|grep ERROR(任意字符) filepath 2,查看目录&授权 file ...