Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李楚霏
/
leetCode_Solution_Record
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c4416e3d
authored
4 years ago
by
李楚霏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
work
parent
2ba644c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
70works/week6/work/decode_ways.js
+22
-0
No files found.
70works/week6/work/decode_ways.js
0 → 100644
View file @
c4416e3d
/**
* @param {string} s
* @return {number}
*/
var
numDecodings
=
function
(
s
)
{
if
(
!
s
)
return
0
;
let
len
=
s
.
length
;
let
dp
=
new
Array
(
len
+
1
).
fill
(
0
);
dp
[
0
]
=
1
;
dp
[
1
]
=
s
[
0
]
===
'0'
?
0
:
1
;
for
(
let
i
=
2
;
i
<=
len
;
i
++
)
{
if
(
s
[
i
-
1
]
!==
'0'
)
{
dp
[
i
]
+=
dp
[
i
-
1
];
}
if
(
s
[
i
-
2
]
===
'1'
||
(
s
[
i
-
2
]
===
'2'
&&
s
[
i
-
1
]
>=
0
&&
s
[
i
-
1
]
<=
6
))
{
dp
[
i
]
+=
dp
[
i
-
2
];
}
}
return
dp
[
len
];
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment