You are viewing a single comment's thread. Return to all comments →
Julia
function happyLadybugs(b) if length(b) == 1 && b[1] !== '_' return "NO" end symbs = Dict() for ch in b if !haskey(symbs,ch) symbs[ch] = 1 else symbs[ch] +=1 end end unhappy_num = 0 for index in eachindex(b) if b[index] !== '_' if !isHappy(b,index) unhappy_num +=1 end end end if unhappy_num>0 && !haskey(symbs,'_') return "NO" end for (index,value) in symbs if index!=='_' && value == 1 return "NO" end end return "YES" end function isHappy(b,index) if index == 1 && b[index+1] === b[index] return true elseif index == length(b) && b[index-1] === b[index] return true elseif index !== 1 && index !== length(b) return b[index-1] === b[index] || b[index+1] === b[index] end return false end
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
Julia