代码拉取完成,页面将自动刷新
/*
9286 - FirstUniqueCharIndex
-------
by jiangshan (@jiangshanmeta) #medium #string
### Question
Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. (Inspired by [leetcode 387](https://leetcode.com/problems/first-unique-character-in-a-string/))
> View on GitHub: https://tsch.js.org/9286
*/
/* _____________ Your Code Here _____________ */
type OneByString<T extends string, U extends string, i extends number[] = []> = T extends `${infer S}${infer R}` ? S extends U ? OneByString<R, U, [...i, 0]> : OneByString<R, U, i> : i['length']
type FirstUniqueCharIndex<T extends string,N extends string = T ,i extends string[] = []> = N extends `${infer S}${infer R}` ? OneByString<T, S> extends 1
? i['length'] : FirstUniqueCharIndex<T,R,[...i, S]> : -1
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<FirstUniqueCharIndex<'leetcode'>, 0>>,
Expect<Equal<FirstUniqueCharIndex<'loveleetcode'>, 2>>,
Expect<Equal<FirstUniqueCharIndex<'aabb'>, -1>>,
Expect<Equal<FirstUniqueCharIndex<''>, -1>>,
Expect<Equal<FirstUniqueCharIndex<'aaa'>, -1>>,
]
/* _____________ Further Steps _____________ */
/*
> Share your solutions: https://tsch.js.org/9286/answer
> View solutions: https://tsch.js.org/9286/solutions
> More Challenges: https://tsch.js.org
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。