[LeetCode]#1309. Decrypt String from Alphabet to Integer Mapping

  • Characters ('a' to 'i') are represented by ('1' to '9') respectively.
  • Characters ('j' to 'z') are represented by ('10#' to '26#') respectively.
Input: s = "10#11#12"
Output: "jkab"
Explanation: "j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2".
  1. In while loop if i < s length and i+2=”#”, this is double digit.
  2. Else is single digit.
  3. use char to covert to letter as below.
class Solution:
def freqAlphabets(self, s):
ans=""
i=0
step=len(s)
while i < step:
if i + 2 < step and s[i + 2] == '#':
ans += chr(int(s[i:i+2]) + 96)
i += 3
else:
ans += chr(int(s[i]) + 96)
i += 1
return ans

--

--

--

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Join the Flote.app

Software development: formal proof vs testing in the wild

AWS: Some Tips for Avoiding Those “Holy Bill” Moments

Kong — Oauth 2.0 Plugin

Gear Monthly Updates: February 2022

Record linkage in Pandas

Part 3 : The Before and After Phase of Content I Edited, Revised, and Proofread for Oracle’s Help…

What is The Best Frontend Option for .Net Backend?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

Hi all, attached below is the code demo for a Hackerrank that I recently attempted.

Non Decreasing Array Leetcode Py

LeetCode #1332 | Remove Palindromic Subsequences

Pattern 7 : Tree Breadth First Search