Skip to content

Commit 5b53aae

Browse files
committed
Add solution 168.
1 parent 308793f commit 5b53aae

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer $n
5+
* @return String
6+
*/
7+
function convertToTitle($n) {
8+
$mapping = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
9+
$sb = "";
10+
while($n > 0) {
11+
$sb .= $mapping [--$n % 26]; //Since for a base 26 the numbers would be from 0 to 25. Deducting 1
12+
$n = intval($n / 26);
13+
}
14+
return strrev($sb);
15+
}
16+
}

0 commit comments

Comments
 (0)