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 54886ac

Browse files
committed
Fix clrf.
1 parent 6ebcb94 commit 54886ac

File tree

21 files changed

+677
-677
lines changed

21 files changed

+677
-677
lines changed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
class Solution {
2-
3-
/**
4-
* @param Integer $x
5-
* @return Boolean
6-
*/
7-
function isPalindrome($x) {
8-
if($x<0) return false;
9-
$i = 0; $rev = 0; $ori = $x;
10-
for($i=10; $x>0; $x= intval($x / 10)){
11-
$rev *= 10;
12-
$rev += $x % $i;
13-
}
14-
return $rev==$ori;
15-
}
1+
class Solution {
2+
3+
/**
4+
* @param Integer $x
5+
* @return Boolean
6+
*/
7+
function isPalindrome($x) {
8+
if($x<0) return false;
9+
$i = 0; $rev = 0; $ori = $x;
10+
for($i=10; $x>0; $x= intval($x / 10)){
11+
$rev *= 10;
12+
$rev += $x % $i;
13+
}
14+
return $rev==$ori;
15+
}
1616
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
class Solution {
2-
3-
/**
4-
* @param String $s
5-
* @param String $p
6-
* @return Boolean
7-
*/
8-
function isMatch($s, $p) {
9-
$dp = array_fill(0, strlen($s) + 1, array_fill(0, strlen($p) + 1, false));
10-
$dp[strlen($s)][strlen($p)] = true;
11-
12-
for ($i = strlen($s); $i >= 0; $i--){
13-
for ($j = strlen($p) - 1; $j >= 0; $j--){
14-
$first_match = ($i < strlen($s) &&
15-
($p[$j] == $s[$i] ||
16-
$p[$j] == '.'));
17-
if ($j + 1 < strlen($p) && $p[$j+1] == '*'){
18-
$dp[$i][$j] = $dp[$i][$j+2] || $first_match && $dp[$i+1][$j];
19-
} else {
20-
$dp[$i][$j] = $first_match && $dp[$i+1][$j+1];
21-
}
22-
}
23-
}
24-
return $dp[0][0];
25-
}
1+
class Solution {
2+
3+
/**
4+
* @param String $s
5+
* @param String $p
6+
* @return Boolean
7+
*/
8+
function isMatch($s, $p) {
9+
$dp = array_fill(0, strlen($s) + 1, array_fill(0, strlen($p) + 1, false));
10+
$dp[strlen($s)][strlen($p)] = true;
11+
12+
for ($i = strlen($s); $i >= 0; $i--){
13+
for ($j = strlen($p) - 1; $j >= 0; $j--){
14+
$first_match = ($i < strlen($s) &&
15+
($p[$j] == $s[$i] ||
16+
$p[$j] == '.'));
17+
if ($j + 1 < strlen($p) && $p[$j+1] == '*'){
18+
$dp[$i][$j] = $dp[$i][$j+2] || $first_match && $dp[$i+1][$j];
19+
} else {
20+
$dp[$i][$j] = $first_match && $dp[$i+1][$j+1];
21+
}
22+
}
23+
}
24+
return $dp[0][0];
25+
}
2626
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
class Solution {
2-
3-
/**
4-
* @param Integer[] $height
5-
* @return Integer
6-
*/
7-
function maxArea($height) {
8-
$maxarea = 0; $l = 0; $r = count($height) - 1;
9-
while ($l < $r) {
10-
$maxarea = max($maxarea, min($height[$l], $height[$r]) * ($r - $l));
11-
if ($height[$l] < $height[$r])
12-
$l++;
13-
else
14-
$r--;
15-
}
16-
return $maxarea;
17-
}
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $height
5+
* @return Integer
6+
*/
7+
function maxArea($height) {
8+
$maxarea = 0; $l = 0; $r = count($height) - 1;
9+
while ($l < $r) {
10+
$maxarea = max($maxarea, min($height[$l], $height[$r]) * ($r - $l));
11+
if ($height[$l] < $height[$r])
12+
$l++;
13+
else
14+
$r--;
15+
}
16+
return $maxarea;
17+
}
1818
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
class Solution {
2-
3-
/**
4-
* @param Integer $num
5-
* @return String
6-
*/
7-
function intToRoman($num) {
8-
$sb = "";
9-
$values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
10-
$roman = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
11-
$i = 0;
12-
13-
while($num > 0){
14-
$repeats = intval($num/$values[$i]);
15-
if($repeats >= 1){
16-
while($repeats != 0){
17-
$sb .= $roman[$i];
18-
$repeats--;
19-
}
20-
$num = $num - intval($num/$values[$i])*$values[$i];
21-
}
22-
$i++;
23-
}
24-
return $sb;
25-
}
1+
class Solution {
2+
3+
/**
4+
* @param Integer $num
5+
* @return String
6+
*/
7+
function intToRoman($num) {
8+
$sb = "";
9+
$values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
10+
$roman = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
11+
$i = 0;
12+
13+
while($num > 0){
14+
$repeats = intval($num/$values[$i]);
15+
if($repeats >= 1){
16+
while($repeats != 0){
17+
$sb .= $roman[$i];
18+
$repeats--;
19+
}
20+
$num = $num - intval($num/$values[$i])*$values[$i];
21+
}
22+
$i++;
23+
}
24+
return $sb;
25+
}
2626
}
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
class Solution {
2-
3-
/**
4-
* @param String $s
5-
* @return Integer
6-
*/
7-
function romanToInt($s) {
8-
$map = [
9-
'I' => 1,
10-
'V' => 5,
11-
'X' => 10,
12-
'L' => 50,
13-
'C' => 100,
14-
'D' => 500,
15-
'M' => 1000];
16-
17-
$result = 0;
18-
for($i = 0; $i < strlen($s); $i++) {
19-
$first = $map[$s[$i]];
20-
if($i <= strlen($s) - 2) {
21-
$second = $map[$s[$i + 1]];
22-
if($second > $first) {
23-
$result += $second - $first;
24-
$i++;
25-
}
26-
else {
27-
$result += $first;
28-
}
29-
}
30-
else
31-
$result += $first;
32-
}
33-
34-
return $result;
35-
}
1+
class Solution {
2+
3+
/**
4+
* @param String $s
5+
* @return Integer
6+
*/
7+
function romanToInt($s) {
8+
$map = [
9+
'I' => 1,
10+
'V' => 5,
11+
'X' => 10,
12+
'L' => 50,
13+
'C' => 100,
14+
'D' => 500,
15+
'M' => 1000];
16+
17+
$result = 0;
18+
for($i = 0; $i < strlen($s); $i++) {
19+
$first = $map[$s[$i]];
20+
if($i <= strlen($s) - 2) {
21+
$second = $map[$s[$i + 1]];
22+
if($second > $first) {
23+
$result += $second - $first;
24+
$i++;
25+
}
26+
else {
27+
$result += $first;
28+
}
29+
}
30+
else
31+
$result += $first;
32+
}
33+
34+
return $result;
35+
}
3636
}
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
class Solution {
2-
3-
/**
4-
* @param String[] $strs
5-
* @return String
6-
*/
7-
function longestCommonPrefix($strs) {
8-
if ($strs == null || count($strs) == 0)
9-
return "";
10-
$minLen = 2147483647;
11-
foreach ($strs as $str) {
12-
$minLen = min($minLen, strlen($str));
13-
}
14-
$low = 1;
15-
$high = $minLen;
16-
while ($low <= $high) {
17-
$middle = intval(($low + $high) / 2);
18-
if (self::isCommonPrefix($strs, $middle))
19-
$low = $middle + 1;
20-
else
21-
$high = $middle - 1;
22-
}
23-
return substr($strs[0], 0, intval(($low + $high) / 2));
24-
}
25-
26-
function isCommonPrefix($strs, $len){
27-
$str1 = substr($strs[0], 0, $len);
28-
for ($i = 1; $i < count($strs); $i++) {
29-
if (!self::startsWith($strs[$i], $str1)) {
30-
return false;
31-
}
32-
}
33-
return true;
34-
}
35-
36-
function startsWith($haystack, $needle) {
37-
return strncmp($haystack, $needle, strlen($needle)) === 0;
38-
}
39-
}
1+
class Solution {
2+
3+
/**
4+
* @param String[] $strs
5+
* @return String
6+
*/
7+
function longestCommonPrefix($strs) {
8+
if ($strs == null || count($strs) == 0)
9+
return "";
10+
$minLen = 2147483647;
11+
foreach ($strs as $str) {
12+
$minLen = min($minLen, strlen($str));
13+
}
14+
$low = 1;
15+
$high = $minLen;
16+
while ($low <= $high) {
17+
$middle = intval(($low + $high) / 2);
18+
if (self::isCommonPrefix($strs, $middle))
19+
$low = $middle + 1;
20+
else
21+
$high = $middle - 1;
22+
}
23+
return substr($strs[0], 0, intval(($low + $high) / 2));
24+
}
25+
26+
function isCommonPrefix($strs, $len){
27+
$str1 = substr($strs[0], 0, $len);
28+
for ($i = 1; $i < count($strs); $i++) {
29+
if (!self::startsWith($strs[$i], $str1)) {
30+
return false;
31+
}
32+
}
33+
return true;
34+
}
35+
36+
function startsWith($haystack, $needle) {
37+
return strncmp($haystack, $needle, strlen($needle)) === 0;
38+
}
39+
}

0 commit comments

Comments
(0)

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