Largest Number

Question

pic

Thoughts

Brute-force

  1. convert number to s
  2. loop through the string, when encounter identical adjacent, try delete that digit and evaluate the new number

another way

for example "2234x563"

if we delete x

  • the number before x -> 563 if not changed
  • the number after x -> 22340000 is divided by 10
  • the number x000 is deleted

This is the basic math formula to get the new number value.

感觉应该是optimal的做法,但是具体还没想好

比如题目的数

223336226

23336226 22336226 22333626

我们在发现第7位的3大于下一个数的2,后面的其实就可以不用比较了。

另一段数字

23336226 2336226 2333626

第4位的6大于3,所以肯定是6的比较大

2133126226 213126226 213312626

第6位的1小于3,所以肯定是下一个数比较大

发现

我们可以发现其中有一个用来比较的数是上一个identical adjacent number的value, 而 另一个数是它之后的那个数.所以我们keep track上一个delete的digit和它后面不identical的 digit,就可以判断当前new number和上一个new number的大小了.就省去了每次生成新value的 过程.

Code