Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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.

posted on 2017-12-23 10:32  Tonix  阅读(126)  评论(0)    收藏  举报