Implement an algorithm , Determine a string s Are all the characters of the are different .

Is there an array of statistics
func isUnique(astr string) bool { var arr int; for _,ch:=range astr{
num:=ch-'a' if(arr[num]==1){ return false } arr[num]++ } return true }
Given two strings s1 and s2, Please write a program , After determining the character rearrangement of one of the strings , Can it be changed into another string .

Record the number of character occurrences , Comparison is enough .
func CheckPermutation(s1 string, s2 string) bool { var arr int; var
brr int; for _,ch:=range s1{ arr[ch-'a']++; } for _,ch:=range s2{
brr[ch-'a']++; } for i:=0;i<26;i++{ if(arr[i]!=brr[i]){ return false; } }
return true; }

URL turn . Write a method , Replace all spaces in the string with %20. It is assumed that there is enough space at the end of the string to hold the new characters , And know the string's “ real ” length .（ notes ： use Java If it comes true , Please use character array implementation , In order to operate directly on the array .）

func replaceSpaces(S string, length int) string { return
strings.ReplaceAll(S[:length], " ", "%20") }
Pay attention to the 8 Yes, it's a pit . dynamic length Arrays cannot be initialized in a way that is in a comment .
func replaceSpaces(S string, length int) string { num := 0 for i:=0;i <length;
i++ { if S[i] == ' ' { num++ } } //var result[2*num + length] byte; result :=
make([]byte, 3*num + (length-num)) k := 0 for i:=0;i <length; i++ { if S[i] ==
' ' { result[k] = '%' result[k+1] = '2' result[k+2] = '0' k += 3 } else {
result[k] = S[i] k++ } } return string(result) }
Given a string , Write a function to determine whether it is one of the permutations of a palindrome string .

Palindrome string refers to words or phrases that are the same in both directions . Arrangement is the rearrangement of letters .

Palindrome strings are not necessarily words in a dictionary .

Examples ：

input ："tactcoa"
output ：true（ There are "tacocat","atcocta", wait ）

thinking ： At most one character has occurred an odd number of times .
func canPermutePalindrome(s string) bool { var arr int; for _,ch:=range
s{ arr[ch]++; } num:=0 for _,i:=range arr{ num+=i%2; } return num<=1; }

Technology
Daily Recommendation
views 5