当前位置:网站首页>2021-12-18: find all letter ectopic words in the string. Given two characters
2021-12-18: find all letter ectopic words in the string. Given two characters
2022-06-23 22:07:00 【Fuda scaffold constructor's daily question】
2021-12-18: Find all alphabetic words in the string .
Given two strings s and p, find s All in p Of Heterotopic words The string of , Returns the starting index of these substrings . Regardless of the order of the answer output .
Heterotopic words A string formed by rearrangement of the same letters ( Include the same string ).
Power button 438.
answer 2021-12-18:
The sliding window . Balance sheet .
Time complexity :O(N).
Spatial complexity :O(1).
The code to use golang To write . The code is as follows :
package main
import "fmt"
func main() {
s := "abab"
p := "ab"
ret := findAnagrams(s, p)
fmt.Println(ret)
}
func findAnagrams(s, p string) []int {
ans := make([]int, 0)
if len(s) < len(p) {
return ans
}
str := []byte(s)
N := len(str)
pst := []byte(p)
M := len(pst)
map0 := make(map[byte]int)
for _, cha := range pst {
map0[cha]++
}
all := M
for end := 0; end < M-1; end++ {
if _, ok := map0[str[end]]; ok {
count := map0[str[end]]
if count > 0 {
all--
}
map0[str[end]] = count - 1
}
}
for end, start := M-1, 0; end < N; end, start = end+1, start+1 {
if _, ok := map0[str[end]]; ok {
count := map0[str[end]]
if count > 0 {
all--
}
map0[str[end]] = count - 1
}
if all == 0 {
ans = append(ans, start)
}
if _, ok := map0[str[start]]; ok {
count := map0[str[start]]
if count >= 0 {
all++
}
map0[str[start]] = count + 1
}
}
return ans
}The results are as follows :
边栏推荐
- v-chart
- Benchclock: a benchmark for evaluating semantic analysis language models
- 嵌入式开发:嵌入式基础——重启和重置的区别
- [js] 生成随机数组
- What is the gold content of PMP certificate
- Intel openvino tool suite advanced course & experiment operation record and learning summary
- How to use zero to build a computer room
- EDI mandatory manual
- 个税怎么算?你知道吗
- How to deal with the situation of repeated streaming and chaotic live broadcast in easydss?
猜你喜欢

Smart cockpit SOC competition upgraded, and domestic 7Nm chips ushered in an important breakthrough

Data visualization: summer without watermelon is not summer

Leetcode algorithm interview sprint sorting algorithm theory (32)

北大、加州伯克利大學等聯合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基於未標記數據的結構化知識的領域自適應文本分類)

万字长文!一文搞懂InheritedWidget 局部刷新机制

Embedded development: embedded foundation -- the difference between restart and reset

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

实验五 模块、包和库

Leetcode must review six lintcode (28348455116385)

How to improve the content quality of short video, these four elements must be achieved
随机推荐
Icml2022 | robust task representation for off-line meta reinforcement learning based on contrastive learning
How ppt creates a visual chart
小程序ssl证书过期是什么原因导致的?小程序ssl证书到期了怎么解决?
Common commands for cleaning up kubernetes cluster resources
Tencent cloud database tdsql elite challenge Q & A (real-time update)
数据可视化之:没有西瓜的夏天不叫夏天
Intel openvino tool suite advanced course & experiment operation record and learning summary
HDLBits-&gt; Circuits-&gt; Arithmetic Circuitd-&gt; 3-bit binary adder
How does the API gateway intercept requests? How does the security of the API gateway reflect?
Relevant logic of transaction code MICn in SAP mm
Performance optimization of database 5- database, table and data migration
After CVM is configured with IPv6, it cannot be accessed as IPv6 or cannot access IPv6 sites
HDLBits-&gt;Circuits-&gt;Arithmetic Circuitd-&gt;3-bit binary adder
How to do API gateway routing? What are the other functions of API gateway?
How the API gateway obtains the URI path and how the API handles local access failure
Simple code and design concept of "back to top"
Tencent cloud server ubuntu18 installs MySQL and logs in remotely
KnowDA: All-in-One Knowledge Mixture Model for Data Augmentation in Few-Shot NLP(KnowDA:用于 Few-Shot NLP 中数据增强的多合一知识混合模型)
Tencent cloud commercial password compliance solution appears at the 2021 high-end Seminar on commercial password application innovation
Error running PyUIC: Cannot start process, the working directory ‘-m PyQt5. uic. pyuic register. ui -o