其他分享
首页 > 其他分享> > 找Bug

找Bug

作者:互联网

https://leetcode-cn.com/problems/ransom-note/

 

func canConstruct(ransomNote string, magazine string) bool {
	m := len(ransomNote)
	n := len(magazine)
	if m > n {
		return false
	}
	index := []int{}
	for i := 0; i < m; i++ {
		ok := false
		for ii := 0; ii < n; ii++ {
			if ransomNote[i] == magazine[ii] {
				j := len(index)
				for iii := 0; iii < j; iii++ {
					if ii != index[iii] {
						index = append(index, ii)
						ok = true
						break
					}
				}
			}
			if ok {
				break
			}
		}
		if !ok {
			return false
		}
	}
	return true
}

  

 

标签:ransomNote,index,false,ii,ok,iii,Bug
来源: https://www.cnblogs.com/rsapaper/p/16155587.html