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 5eee963

Browse files
authored
Merge pull request #4 from doocs/master
merge
2 parents 0a8700c + 64e0170 commit 5eee963

File tree

14 files changed

+276
-6
lines changed

14 files changed

+276
-6
lines changed

‎.github/workflows/sync.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Sync to Gitee
11+
- name: Sync to gitee.com
1212
uses: wearerequired/git-mirror-action@master
1313
env:
14-
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
14+
SSH_PRIVATE_KEY: ${{ secrets.RSA_PRIVATE_KEY }}
1515
with:
1616
source-repo: "git@github.com:doocs/leetcode.git"
1717
destination-repo: "git@gitee.com:Doocs/leetcode.git"

‎basic/sort/QuickSort.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.Arrays;
2+
3+
public class QuickSort {
4+
5+
private static void quickSort(int[] nums) {
6+
quickSort(nums, 0, nums.length - 1);
7+
}
8+
9+
private static void quickSort(int[] nums, int low, int high) {
10+
if (low >= high) {
11+
return;
12+
}
13+
int[] p = partition(nums, low, high);
14+
quickSort(nums, low, p[0] - 1);
15+
quickSort(nums, p[0] + 1, high);
16+
}
17+
18+
private static int[] partition(int[] nums, int low, int high) {
19+
int less = low - 1, more = high;
20+
21+
while (low < more) {
22+
if (nums[low] < nums[high]) {
23+
swap(nums, ++less, low++);
24+
} else if (nums[low] > nums[high]) {
25+
swap(nums, --more, low);
26+
} else {
27+
++low;
28+
}
29+
}
30+
swap(nums, more, high);
31+
return new int[] {less + 1, more};
32+
}
33+
34+
private static void swap(int[] nums, int i, int j) {
35+
int t = nums[i];
36+
nums[i] = nums[j];
37+
nums[j] = t;
38+
}
39+
40+
public static void main(String[] args) {
41+
int[] nums = {1, 2, 7, 4, 5, 3};
42+
quickSort(nums);
43+
System.out.println(Arrays.toString(nums));
44+
}
45+
}

‎lcci/01.02.Check Permutation/README.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,18 @@ class Solution:
4141
<!-- 这里可写当前语言的特殊实现逻辑 -->
4242

4343
```java
44-
44+
class Solution {
45+
public boolean checkPermutation(String s1, String s2) {
46+
if (s1 == null || s2 == null || s1.length() != s2.length()) {
47+
return false;
48+
}
49+
char[] c1 = s1.toCharArray();
50+
char[] c2 = s2.toCharArray();
51+
Arrays.sort(c1);
52+
Arrays.sort(c2);
53+
return Arrays.equals(c1, c2);
54+
}
55+
}
4556
```
4657

4758
### ...

‎lcci/01.02.Check Permutation/README_EN.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@ class Solution:
5656
### Java
5757

5858
```java
59-
59+
class Solution {
60+
public boolean CheckPermutation(String s1, String s2) {
61+
if (s1 == null || s2 == null || s1.length() != s2.length()) {
62+
return false;
63+
}
64+
char[] c1 = s1.toCharArray();
65+
char[] c2 = s2.toCharArray();
66+
Arrays.sort(c1);
67+
Arrays.sort(c2);
68+
return Arrays.equals(c1, c2);
69+
}
70+
}
6071
```
6172

6273
### ...
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public boolean CheckPermutation(String s1, String s2) {
3+
if (s1 == null || s2 == null || s1.length() != s2.length()) {
4+
return false;
5+
}
6+
char[] c1 = s1.toCharArray();
7+
char[] c2 = s2.toCharArray();
8+
Arrays.sort(c1);
9+
Arrays.sort(c2);
10+
return Arrays.equals(c1, c2);
11+
}
12+
}

‎lcci/01.03.String to URL/README.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,22 @@ class Solution:
4141
<!-- 这里可写当前语言的特殊实现逻辑 -->
4242

4343
```java
44-
44+
class Solution {
45+
public String replaceSpaces(String S, int length) {
46+
char[] c = S.toCharArray();
47+
int j = c.length;
48+
for (int i = length - 1; i >= 0; i--) {
49+
if (c[i] == ' ') {
50+
c[--j] = '0';
51+
c[--j] = '2';
52+
c[--j] = '%';
53+
} else {
54+
c[--j] = c[i];
55+
}
56+
}
57+
return new String(c, j, c.length - j);
58+
}
59+
}
4560
```
4661

4762
### ...

‎lcci/01.03.String to URL/README_EN.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,22 @@ class Solution:
6767
### Java
6868

6969
```java
70-
70+
class Solution {
71+
public String replaceSpaces(String S, int length) {
72+
char[] c = S.toCharArray();
73+
int j = c.length;
74+
for (int i = length - 1; i >= 0; i--) {
75+
if (c[i] == ' ') {
76+
c[--j] = '0';
77+
c[--j] = '2';
78+
c[--j] = '%';
79+
} else {
80+
c[--j] = c[i];
81+
}
82+
}
83+
return new String(c, j, c.length - j);
84+
}
85+
}
7186
```
7287

7388
### ...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public String replaceSpaces(String S, int length) {
3+
char[] c = S.toCharArray();
4+
int j = c.length;
5+
for (int i = length - 1; i >= 0; i--) {
6+
if (c[i] == ' ') {
7+
c[--j] = '0';
8+
c[--j] = '2';
9+
c[--j] = '%';
10+
} else {
11+
c[--j] = c[i];
12+
}
13+
}
14+
return new String(c, j, c.length - j);
15+
}
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution
2+
{
3+
public:
4+
vector<int> spiralOrder(vector<vector<int>> &matrix)
5+
{
6+
vector<int> ans;
7+
if (matrix.size() == 0)
8+
return ans;
9+
int left = 0, top = 0, bottom = matrix.size() - 1, right = matrix[0].size() - 1;
10+
while (true)
11+
{
12+
for (int i = left; i <= right; i++)
13+
ans.push_back(matrix[top][i]);
14+
top++;
15+
if (top > bottom)
16+
break;
17+
for (int i = top; i <= bottom; i++)
18+
ans.push_back(matrix[i][right]);
19+
right--;
20+
if (right < left)
21+
break;
22+
for (int i = right; i >= left; i--)
23+
ans.push_back(matrix[bottom][i]);
24+
bottom--;
25+
if (bottom < top)
26+
break;
27+
for (int i = bottom; i >= top; i--)
28+
ans.push_back(matrix[i][left]);
29+
left++;
30+
if (left > right)
31+
break;
32+
}
33+
return ans;
34+
}
35+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
impl Solution {
2+
pub fn spiral_order(matrix: Vec<Vec<i32>>) -> Vec<i32> {
3+
let mut ans=Vec::new();
4+
if matrix.len()==0{
5+
return ans;
6+
}
7+
let (mut left,mut right,mut top,mut bottom)=(0,matrix[0].len()-1,0,matrix.len()-1);
8+
loop{
9+
for i in left..right+1{
10+
ans.push(matrix[top][i]);
11+
}
12+
top+=1;
13+
if (top as i32)>(bottom as i32){
14+
break;
15+
}
16+
for i in top..bottom+1{
17+
ans.push(matrix[i][right]);
18+
}
19+
right-=1;
20+
if (right as i32)<(left as i32){
21+
break;
22+
}
23+
for i in (left..right+1).rev(){
24+
ans.push(matrix[bottom][i]);
25+
}
26+
bottom-=1;
27+
if (bottom as i32)<(top as i32){
28+
break;
29+
}
30+
for i in (top..bottom+1).rev(){
31+
ans.push(matrix[i][left]);
32+
}
33+
left+=1;
34+
if (left as i32)>(right as i32){
35+
break;
36+
}
37+
}
38+
ans
39+
}
40+
}

0 commit comments

Comments
(0)

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