decode ways javascript
/**
* @param {string} s
* @return {number}
*/
var numDecodings = function(s) {
var len = s.length;
var tmp = 0;
var tmp1 = 1;
var tmp2 = 0;
var num1 = 0;
var num2 = 0;
if (s === '' || s[0] === '0') return 0;
for (var i = 1; i <= len; i++) {
num1 = Number(s.substr(i - 1, 1));
num2 = Number(s.substr(i - 2, 2));
if (num1 !== 0) tmp += tmp1;
if (10 <= num2 && num2 <= 26) tmp += tmp2;
tmp2 = tmp1;
tmp1 = tmp;
tmp = 0;
}
return tmp1;
};
Also in JavaScript:
- how to check is the key of a localstorage is emopty
- Javascript generate random string
- add bootstrap to gatsby
- 14. Write a JavaScript function to find the difference of two arrays. Test Data : console.log(difference([1, 2, 3], [100, 2, 1, 10])); ["3", "10", "100"]
- 3 = signs in javasdcript
- react native seperator code
- get date format javascript
- convert a string to array in javascript
- how to get value from json object
- creating a nested loop of a chessboard in javascript
- javascript get unique items of array
- how to check if 2 sprites are touching js
- javascript convert number to spreadsheet column
- start angular app server
- read json pandas
- comment dire le nombre de ligne html en cliquamt sur un boutton javascript
- turning an hex code to rgb discord.js
- increment operator in javascript
- outer.use() requires a middleware function but got a Object
- ejs / javascript check if array/object exists and is not empty
- how to give css style in javascript
- create server and connect to db and frontend
- convert shp to geojson python
- what 1hr in milliseconds in javascript