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

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

  2. Leetcode821.Shortest Distance to a Character字符的最短距离

    给定一个字符串 S 和一个字符 C.返回一个代表字符串 S 中每个字符到字符串 S 中的字符 C 的最短距离的数组. 示例 1: 输入: S = "loveleetcode", C ...

随机推荐

  1. 打造万能的Python开发环境

    一.下载与安装 python的版本众多,主流的分2和3,还有各种小版本. django等也有众多版本. 在我们开发过程中,为使用不同的版本测试,在一台电脑上进行只能进行替换. 为了简化.我们使用con ...

  2. mysql 自查询

    先介绍用法: 用法解释  select  * from  a,b  : shopping 商品表 , baixitest SELECT b.name from shopping as a, baixi ...

  3. 【lightoj-1025】The Specials Menu(区间DP)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1025 [题目大意] 求一个字符串删去任意字符可以构成多少个不同的回文串 [分析 ...

  4. Context的作用

    context用于访问全局资源 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceSta ...

  5. socket INADDR_ANY

    linux下的socket INADDR_ANY表示的是一个服务器上所有的网卡(服务器可能不止一个网卡)多个本地ip地址都进行绑定端口号,进行侦听. 不光是多个网卡的问题. 见如下server lis ...

  6. 关于 self = [super init];

    [plain] view plaincopyprint? - (id)init { self = [super init]; // Call a designated initializer here ...

  7. ACM学习历程—HDU5701 中位数计数(中位数 && 计数排序)

    http://acm.hdu.edu.cn/showproblem.php?pid=5701 这是这次百度之星初赛2B的第六题.之前白山云做过类似的题,省赛完回来,我看了一下大概就有这样的思路:首先枚 ...

  8. xcomponent web 跨域组件介绍

    1. 项目地址: https://github.com/krakenjs/xcomponent 2. 支持的特性 a. Render an iframe or popup on a different ...

  9. mysql时间运算

    DELETE FROM zhongqiu WHERE caretatime<=ADDDATE(NOW(),-14) caretatime` timestamp NOT NULL DEFAULT ...

  10. zabbix 执行自定义key脚本超时

    报错如下: [root@master scripts]# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -k web.site.code[www.baid ...