z*********n 发帖数: 1451 | 1 直接上干货, leetcode已经有这题了 (* 代表1~9 而非0~9),这是我过了的一个解:
class Solution {
int base = 1000000007;
public:
int numDecodings(string s) {
//last1: decode ways of s ending at i-1, last2 decode ways of s
ending at i-2, nlast1 : next last1.
long long last1 = 1, last2 = 1, nlast1 = 0; //there is only 1 way to
decode "", so initialized with 1.
for (int i = 0; i < s.size(); ++ i)
{
//Just look at current character
if (s[i] == '*')
nla... 阅读全帖 |
|
r****t 发帖数: 10904 | 2 可能是无递归的最简解法,因为 python int 不限大小,可随便上至 octillion,
whatever
import locale
eng = { '0': '', '1': 'one', '2': 'two', '3': 'three', '4': 'four',
'5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '10':
'ten', '11': 'eleven', '12': 'twelve', '13': 'thirteen', '14': 'forteen',
'15': 'fifteen', '16': 'sixteen', '17': 'seventeen', '18': 'eighteen',
'19': 'nineteen', '20': 'twenty', '30': 'thirty', '40': 'forty',
'50': 'fifty', '60': 'sixty', '70': 'seventy', '80': 'eighty','90': 'nighty'
, ... 阅读全帖 |
|