本文准备讲解1个简单的算法编程问题, 这个算法编程问题来自LintCode平台。不了解.LintCode平台的读者可以阅读笔者文章(在线编程平台推荐-LeetCode)。问题的英文版本描述如下:
Delete Digits
Given string A ( a positive integer ) which has N digits, remove any k digits of the number, the remaining digits are arranged according to the original order to become a new positive integer.
Each removal will get the smallest integer.
Find the smallest integer after remove k digits.
N<= 240 and k<=N,
Example
Given an integer A ="178542", k =4
return a string "12"
删除数字
给出一个字符串A, 表示一个n位正整数。删除其中k位数字, 使得剩余的数字仍然按照原来的顺序排列,产生一个新的正整数。
要求每次删除数字后获得最小的数。
找到删除k个数字之后的最小正整数。
N<= 240,k<=N
样例
给出一个字符串代表的正整数A和一个整数k, 其中A = 178542,k = 4
返回一个字符串"12"
网友评论