package main
import (
"fmt"
)
func stringIntersection(s1, s2 string) string {
// Use a map to track characters in the first string
charMap := make(map[rune]bool)
for _, char := range s1 {
charMap[char] = true
}
// Find common characters in the second string
intersection := ""
for _, char := range s2 {
if charMap[char] {
intersection += string(char)
// Remove the character to avoid duplicates
delete(charMap, char)
}
}
return intersection
}
func main() {
str1 := "php"
str2 := "python"
result := stringIntersection(str1, str2)
fmt.Println("Intersection:", result)
}
/*
run:
Intersection: ph
*/