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 ... 
随机推荐
- LeetCode OJ:Simplify Path(简化路径)
			Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ... 
- LeetCode OJ:Count Primes(质数计数)
			Count the number of prime numbers less than a non-negative number, n. 计算小于n的质数的个数,当然就要用到大名鼎鼎的筛法了,代码如 ... 
- 解决 jsonP 安全问题
			jsonp安全性防范,分为以下几点: 1.防止callback参数意外截断js代码,特殊字符单引号双引号,换行符均存在风险 2.防止callback参数恶意添加标签(如script),造成XSS漏洞 ... 
- Leetcode 1019. Next Greater Node In Linked List
			单调栈的应用. class Solution: def nextLargerNodes(self, head: ListNode) -> List[int]: stack = [] ret = ... 
- asp.net 禁止回车输入
			//只在输入框禁止输入回车 if(event.keyCode==13&&event.srcElement.type=="textarea") { ... 
- 【MFC】vs2013_MFC使用文件之15.mfc 按钮CBitmapButton的使用
			本文是基于对话框的 博文基于 无幻 的博文为基础写的 http://blog.csdn.net/akof1314/article/details/4951836 笔者使用mfc撑死2个星期,不过这是有 ... 
- MyBatis对多关系:显示该用户的所有角色
			只要在一边的UserMapper.xml 配置好就可以了 <?xml version="1.0" encoding="UTF-8" ?> <! ... 
- 快排的python实现
			快排的python实现 #python 2.7 def quick_sort(L): if len(L) <= 1: return L else: return quick_sort([lt f ... 
- 深入理解java虚拟机-第八章
			第8章 虚拟机字节码执行引擎 8.2 运行时栈帧结构 栈帧(Stack Frame)是用于支持虚拟机进行方法调用和方法执行的数据结构. 每一个栈帧包括了局部变量表.操作数栈.动态连接.方法返回地址和一 ... 
- 剑指Offer面试题:8.二进制中1的个数
			一 题目:二进制中1的个数 题目:请实现一个整数,输出该数二进制表示中1的个数.例如把9表示成二进制是1001,有2位是1.因此如果输入9,该函数输出2. 二 可能引起死循环的解法 // 计算整数的二 ... 
