Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 82a2597

Browse files
committed
3498
1 parent 185282f commit 82a2597

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
class Solution
3+
{
4+
/**
5+
* @param String $s
6+
* @return Integer
7+
*/
8+
public function reverseDegree($s)
9+
{
10+
$n = strlen($s);
11+
12+
$sum = 0;
13+
14+
$oz = ord('z') ;
15+
16+
for ($i = 0; $i < $n; $i++) {
17+
18+
$value = $oz - ord($s[$i]) + 1;
19+
20+
$sum += $value * ($i +1);
21+
}
22+
return $sum;
23+
}
24+
}
25+
26+
// Example usage:
27+
$solution = new Solution();
28+
29+
echo $solution->reverseDegree("abc"); // Output: 5

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /