原文:[LeetCode] 402. Remove K Digits 去掉K位數字

Given a non negative integernumrepresented as a string, removekdigits from the number so that the new number is the smallest possible. Note: The length ofnumis less than and will be k. The givennumdo ...

2016-09-19 04:04 4 13796 推薦指數:

查看詳情

LeetCode402、移除K位數字

1、移除K位數字 題目:402. 移掉K位數字 題目描述:   給定一個以字符串表示的非負整數 num,移除這個數中的 k 位數字,使得剩下的數字最小。(num 的長度小於 10002 且 ≥ k。 num 不會包含任何前導零。) 示例 : 解題思路:基於單調棧的貪心 ...

Wed Mar 25 02:05:00 CST 2020 0 596
[LeetCode] Add Digits數字

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Follow up:Could you do ...

Wed Aug 19 07:36:00 CST 2015 6 13996
一個n位的數,去掉其中的k位,問怎樣去使得留下來的(n-k位數按原來的前后順序組成的數最小

例如 8314925去掉4個數,留下125最小,注意有前后順序要求,要是沒有順序當然是123。 解決方案 貪心算法,在每次被訪問的位置保證有最優解。 思路一 分析:求一共n位,求其中的m位組成的數最小。那么這個m位的數,最高位應該在原數的最高位到第m位區間找,要不然就不能當第m位 ...

Thu Mar 06 02:07:00 CST 2014 10 3973
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM