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 03e9ef7

Browse files
Merge branch 'youngyangyang04:master' into master
2 parents e81c784 + f85b5a2 commit 03e9ef7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

‎problems/0344.反转字符串.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,38 @@ public class Solution
266266
}
267267
}
268268
```
269+
270+
271+
PHP:
272+
```php
273+
// 双指针
274+
// 一:
275+
function reverseString(&$s) {
276+
$left = 0;
277+
$right = count($s)-1;
278+
while($left<$right){
279+
$temp = $s[$left];
280+
$s[$left] = $s[$right];
281+
$s[$right] = $temp;
282+
$left++;
283+
$right--;
284+
}
285+
}
286+
287+
// 二:
288+
function reverseString(&$s) {
289+
$this->reverse($s,0,count($s)-1);
290+
}
291+
// 按指定位置交换元素
292+
function reverse(&$s, $start, $end) {
293+
for ($i = $start, $j = $end; $i < $j; $i++, $j--) {
294+
$tmp = $s[$i];
295+
$s[$i] = $s[$j];
296+
$s[$j] = $tmp;
297+
}
298+
}
299+
```
300+
269301
Scala:
270302
```scala
271303
object Solution {

‎problems/0941.有效的山脉数组.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,26 @@ var validMountainArray = function(arr) {
157157
};
158158
```
159159

160+
## TypeScript
161+
162+
```typescript
163+
function validMountainArray(arr: number[]): boolean {
164+
const length: number = arr.length;
165+
if (length < 3) return false;
166+
let left: number = 0,
167+
right: number = length - 1;
168+
while (left < (length - 1) && arr[left] < arr[left + 1]) {
169+
left++;
170+
}
171+
while (right > 0 && arr[right] < arr[right - 1]) {
172+
right--;
173+
}
174+
if (left === right && left !== 0 && right !== length - 1)
175+
return true;
176+
return false;
177+
};
178+
```
179+
160180

161181

162182

0 commit comments

Comments
(0)

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