您的位置:首页 > 其它

HackerRank "Richie Rich"

2017-12-23 10:32 399 查看
Fun Greedy. My first thought was a DFS based solution... however the editorial provides a super neat 2-pass O(n) solution:

Pass 1: if s[l] != s[r], change the smaller one into the bigger one.
Pass 2: check k. if k > 0, we change as many chars into '9'

Split one convoluted problem into 2 easier one.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: