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. SurfaceView基本使用--动态画正弦函数

    package com.zzw.TestSurfaceView; import android.content.Context; import android.graphics.Canvas; imp ...

  2. html03表单

    <!DOCTYPE HTML> <html> <head> <title>用户登录的表单</title> </head> < ...

  3. Android 中Activity,Window和View之间的关系

    转自:http://hi.baidu.com/xiaofanqing/blog/item/8261ac114ab14f64cb80c435.html 我这里根据我个人的理解来讲讲我个人对这3个概念的理 ...

  4. Python基础学习(第1天)

    写这篇随笔,是看Vamei大大写的Python快速教程的学习笔记,以此自勉,链接:http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.htm ...

  5. uid

    var uid = 0 function nextUid() { return ++uid }

  6. 使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard环境

    Duplication Database 介绍 Duplicate database可以按照用途分为2种: duplicate database(复制出一个数据库) duplicate standby ...

  7. noip济南清北冲刺班DAY2

    题解: 贪心+dp 30% N<=5  5!枚举一下 20%  高度没有的时候,高度花费就不存在了,将ci排序, 从小到大挨个跳.另外,20% 准备跳楼没有花费,那么跳 楼的高度一定是从小到大, ...

  8. django的表与表之间的关系详细讲解

    转:http://www.cnblogs.com/feixuelove1009/p/5855295.html

  9. fn project Function files 说明

    主要是文件 func.yaml func.json 详细说明如下: An example of a function file: name: fnproject/hello version: 0.0. ...

  10. matlab_移动文件和复制文件

    clear clc cd('C:\Users\xx\Desktop\learning'); % 设置当前目录 % 此时learning文件夹中有:文件夹x, 文件夹y, 文件a.png, 文件b.pn ...