class Solution
{
public:
vector<int> shortestToChar(string S, char C)
{
int len=S.length();
vector<int>res(len,-); //as the result vector
vector<int> cindex; //save the index of C
for(int i=;i<len;i++) //write the distance of C and build the cindex
if(S[i]==C)
{
cindex.push_back(i);
res[i]=;
}
int szindex=cindex.size(); int count=;
for(int j=cindex[]-;j>=;j--) //write the distance before the first C
res[j]=count++; count=;
for(int k=cindex[szindex-]+;k<len;k++) //write the distance after the last C
res[k]=count++; for(int x=;x<szindex;x++) //write the distance between two C
{
count=;
int left=cindex[x-]+,right=cindex[x]-;
while(left<=right)
{
res[left++]=count;
res[right--]=count++;
}
}
return res;
}
};

最新文章

  1. MVC-命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Html”(是否缺少程序集引用?)
  2. C# MVC jsonp初接触成功
  3. json与对象转化
  4. JavaWeb高级:Servlet源码分析
  5. jsp中自定义Taglib案例
  6. [Linux Tips] 1. 查看端口
  7. ANSI
  8. 10大iOS开发者最喜爱的类库
  9. 树莓派(Rospberry Pi B+)到货亲測
  10. jQuery 分步引导 插件
  11. MessageDigest简要
  12. Appium入门示例(Java)
  13. java多线程的(一)-之java线程的使用
  14. 【Unity Shaders】游戏性和画面特效——创建一个老电影式的画面特效
  15. go-mysql,一个易用的mysql接口框架实现
  16. 第七节:语法总结(1)(自动属性、out参数、对象初始化器、var和dynamic等)
  17. centos服务器监控 服务器虚拟机里面的客户端zabbix-agent安装
  18. SSH高级服务
  19. CF113D 高斯消元、dp
  20. Iris分类以及数组reshape想到的

热门文章

  1. LibreOJ 6282. 数列分块入门 6
  2. SQL Server中row_number的用法
  3. C++ 计算直线的交点数(动态规划)
  4. 数据节点-df 无法输出结果
  5. Mysql自定义函数functions时报错
  6. .NET通用工具——正则表达式
  7. LIS LCS 最长上升子序列 最长公共子序列 ...
  8. 认识Thymeleaf:简单表达式和标签 基础信息
  9. 1F - A+B for Input-Output Practice (III)
  10. stl中顺序性容器,关联容器两者粗略解释