Skip to content

Commit 85e6b6d

Browse files
committed
feat: add python and java solutions to leetcode problem: No.1299
1 parent 8faf4f6 commit 85e6b6d

File tree

6 files changed

+73
-27
lines changed

6 files changed

+73
-27
lines changed

README.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
</p>
44

55
<p align="center">
6-
<a href="https://github.com/doocs/leetcode"><img src="https://badgen.net/badge/langs/Java,Python,C++,JavaScript,Go,.../green?list=1" alt="languages"></a>
7-
<a href="https://opencollective.com/doocs-leetcode/backers/badge.svg" alt="backers on Open Collective"><img src="https://opencollective.com/doocs-leetcode/backers/badge.svg" /></a>
8-
<a href="https://opencollective.com/doocs-leetcode/sponsors/badge.svg" alt="Sponsors on Open Collective"><img src="https://opencollective.com/doocs-leetcode/sponsors/badge.svg" /></a>
9-
<a href="https://github.com/doocs/leetcode/blob/main/LICENSE"><img src="https://badgen.net/github/license/doocs/leetcode?color=green" alt="LICENSE"></a><br>
10-
<a href="https://github.com/doocs/leetcode/stargazers"><img src="https://badgen.net/github/stars/doocs/leetcode?color=cyan&cache=300" alt="stars"></a>
11-
<a href="https://github.com/doocs/leetcode/network/members"><img src="https://badgen.net/github/forks/doocs/leetcode?color=cyan&cache=300" alt="forks"></a>
12-
<a href="https://github.com/doocs/leetcode"><img src="https://badgen.net/badge/⭐/GitHub/cyan" alt="github"></a>
13-
<a href="https://gitee.com/doocs/leetcode"><img src="https://badgen.net/badge/⭐/Gitee/cyan" alt="github"></a>
14-
<a href="http://makeapullrequest.com"><img src="https://badgen.net/badge/PRs/welcome/cyan" alt="PRs Welcome"></a>
15-
<a href="https://doocs.github.io/#/?id=how-to-join"><img src="https://badgen.net/badge/organization/join%20us/cyan" alt="open-source-organization"></a>
6+
<a href="https://github.com/doocs/leetcode"><img src="https://img.shields.io/badge/langs-Java%20%7C%20Python%20%7C%20C%2B%2B%20%7C%20JavaScript%20%7C%20Go%20%7C%20...-red?style=flat-square&color=42b883" alt="languages"></a>
7+
<a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/prs-welcome-42b883?style=flat-square" alt="PRs Welcome"></a>
8+
<a href="https://doocs.github.io/#/?id=how-to-join"><img src="https://img.shields.io/badge/organization-join%20us-42b883?style=flat-square" alt="open-source-organization"></a>
9+
<a href="https://github.com/doocs/leetcode/blob/main/LICENSE"><img src="https://img.shields.io/github/license/doocs/leetcode?color=42b883&style=flat-square" alt="LICENSE"></a><br>
10+
<a href="https://opencollective.com/doocs-leetcode/backers/badge.svg" alt="backers on Open Collective"><img src="https://img.shields.io/opencollective/backers/doocs-leetcode?color=42b883&style=flat-square&logo=open%20collective&logoColor=ffffff" /></a>
11+
<a href="https://github.com/doocs/leetcode/stargazers"><img src="https://img.shields.io/github/stars/doocs/leetcode?color=42b883&logo=github&style=flat-square" alt="stars"></a>
12+
<a href="https://github.com/doocs/leetcode/network/members"><img src="https://img.shields.io/github/forks/doocs/leetcode?color=42b883&logo=github&style=flat-square" alt="forks"></a>
13+
<a href="https://opencollective.com/doocs-leetcode/sponsors/badge.svg" alt="Sponsors on Open Collective"><img src="https://img.shields.io/opencollective/sponsors/doocs-leetcode?color=42b883&style=flat-square&logo=open%20collective&logoColor=ffffff" /></a>
1614
</p>
1715

1816
## 介绍

README_EN.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
</p>
44

55
<p align="center">
6-
<a href="https://github.com/doocs/leetcode"><img src="https://badgen.net/badge/langs/Java,Python,C++,JavaScript,Go,.../green?list=1" alt="languages"></a>
7-
<a href="https://opencollective.com/doocs-leetcode/backers/badge.svg" alt="backers on Open Collective"><img src="https://opencollective.com/doocs-leetcode/backers/badge.svg" /></a>
8-
<a href="https://opencollective.com/doocs-leetcode/sponsors/badge.svg" alt="Sponsors on Open Collective"><img src="https://opencollective.com/doocs-leetcode/sponsors/badge.svg" /></a>
9-
<a href="https://github.com/doocs/leetcode/blob/main/LICENSE"><img src="https://badgen.net/github/license/doocs/leetcode?color=green" alt="LICENSE"></a><br>
10-
<a href="https://github.com/doocs/leetcode/stargazers"><img src="https://badgen.net/github/stars/doocs/leetcode?color=cyan&cache=300" alt="stars"></a>
11-
<a href="https://github.com/doocs/leetcode/network/members"><img src="https://badgen.net/github/forks/doocs/leetcode?color=cyan&cache=300" alt="forks"></a>
12-
<a href="https://github.com/doocs/leetcode"><img src="https://badgen.net/badge/⭐/GitHub/cyan" alt="github"></a>
13-
<a href="https://gitee.com/doocs/leetcode"><img src="https://badgen.net/badge/⭐/Gitee/cyan" alt="github"></a>
14-
<a href="http://makeapullrequest.com"><img src="https://badgen.net/badge/PRs/welcome/cyan" alt="PRs Welcome"></a>
15-
<a href="https://doocs.github.io/#/?id=how-to-join"><img src="https://badgen.net/badge/organization/join%20us/cyan" alt="open-source-organization"></a>
6+
<a href="https://github.com/doocs/leetcode"><img src="https://img.shields.io/badge/langs-Java%20%7C%20Python%20%7C%20C%2B%2B%20%7C%20JavaScript%20%7C%20Go%20%7C%20...-red?style=flat-square&color=42b883" alt="languages"></a>
7+
<a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/prs-welcome-42b883?style=flat-square" alt="PRs Welcome"></a>
8+
<a href="https://doocs.github.io/#/?id=how-to-join"><img src="https://img.shields.io/badge/organization-join%20us-42b883?style=flat-square" alt="open-source-organization"></a>
9+
<a href="https://github.com/doocs/leetcode/blob/main/LICENSE"><img src="https://img.shields.io/github/license/doocs/leetcode?color=42b883&style=flat-square" alt="LICENSE"></a><br>
10+
<a href="https://opencollective.com/doocs-leetcode/backers/badge.svg" alt="backers on Open Collective"><img src="https://img.shields.io/opencollective/backers/doocs-leetcode?color=42b883&style=flat-square&logo=open%20collective&logoColor=ffffff" /></a>
11+
<a href="https://github.com/doocs/leetcode/stargazers"><img src="https://img.shields.io/github/stars/doocs/leetcode?color=42b883&logo=github&style=flat-square" alt="stars"></a>
12+
<a href="https://github.com/doocs/leetcode/network/members"><img src="https://img.shields.io/github/forks/doocs/leetcode?color=42b883&logo=github&style=flat-square" alt="forks"></a>
13+
<a href="https://opencollective.com/doocs-leetcode/sponsors/badge.svg" alt="Sponsors on Open Collective"><img src="https://img.shields.io/opencollective/sponsors/doocs-leetcode?color=42b883&style=flat-square&logo=open%20collective&logoColor=ffffff" /></a>
1614
</p>
1715

1816
## Introduction
@@ -30,8 +28,8 @@ Complete solutions to [LeetCode](https://leetcode-cn.com/problemset/all/), [LCOF
3028
## Solutions
3129

3230
- [LeetCode](/solution/README_EN.md)
33-
- [LCOF: _Coding Interviews, 2nd Edition_](/lcof/README_EN.md)
34-
- [LCCI: _Cracking the Coding Interview, 6th Edition_](/lcci/README_EN.md)
31+
- [LCOF: Coding Interviews, 2nd Edition](/lcof/README_EN.md)
32+
- [LCCI: Cracking the Coding Interview, 6th Edition](/lcci/README_EN.md)
3533

3634
## Basic Algorithms
3735

@@ -156,7 +154,7 @@ I'm looking for long-term contributors/partners to this repo! Send me [PRs](http
156154

157155
1. <kbd>Fork</kbd> [this repository](https://github.com/doocs/leetcode) to your own GitHub account and then <kbd>clone</kbd> it to your local machine.
158156
1. Make some changes to your leetcode repository, then <kbd>add</kbd>, <kbd>commit</kbd> and <kbd>push</kbd> the changes to your remote GitHub repository.
159-
1. Submit a pull request with your changes!
157+
1. Create a pull request with your changes!
160158
1. See [CONTRIBUTING](https://github.com/doocs/.github/blob/main/CONTRIBUTING.md) or [GitHub Help](https://help.github.com/en) for more details.
161159

162160
<p align="center">

solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,31 @@
3838
<!-- 这里可写当前语言的特殊实现逻辑 -->
3939

4040
```python
41-
41+
class Solution:
42+
def replaceElements(self, arr: List[int]) -> List[int]:
43+
m = -1
44+
for i in range(len(arr) - 1, -1, -1):
45+
t = arr[i]
46+
arr[i] = m
47+
m = max(m, t)
48+
return arr
4249
```
4350

4451
### **Java**
4552

4653
<!-- 这里可写当前语言的特殊实现逻辑 -->
4754

4855
```java
49-
56+
class Solution {
57+
public int[] replaceElements(int[] arr) {
58+
for (int i = arr.length - 1, max = -1; i >= 0; --i) {
59+
int t = arr[i];
60+
arr[i] = max;
61+
max = Math.max(max, t);
62+
}
63+
return arr;
64+
}
65+
}
5066
```
5167

5268
### **...**

solution/1200-1299/1299.Replace Elements with Greatest Element on Right Side/README_EN.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,29 @@
3434
### **Python3**
3535

3636
```python
37-
37+
class Solution:
38+
def replaceElements(self, arr: List[int]) -> List[int]:
39+
m = -1
40+
for i in range(len(arr) - 1, -1, -1):
41+
t = arr[i]
42+
arr[i] = m
43+
m = max(m, t)
44+
return arr
3845
```
3946

4047
### **Java**
4148

4249
```java
43-
50+
class Solution {
51+
public int[] replaceElements(int[] arr) {
52+
for (int i = arr.length - 1, max = -1; i >= 0; --i) {
53+
int t = arr[i];
54+
arr[i] = max;
55+
max = Math.max(max, t);
56+
}
57+
return arr;
58+
}
59+
}
4460
```
4561

4662
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public int[] replaceElements(int[] arr) {
3+
for (int i = arr.length - 1, max = -1; i >= 0; --i) {
4+
int t = arr[i];
5+
arr[i] = max;
6+
max = Math.max(max, t);
7+
}
8+
return arr;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def replaceElements(self, arr: List[int]) -> List[int]:
3+
m = -1
4+
for i in range(len(arr) - 1, -1, -1):
5+
t = arr[i]
6+
arr[i] = m
7+
m = max(m, t)
8+
return arr

0 commit comments

Comments
 (0)