Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ABOUTME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 关于我

【关于自己】:大家好,我是刘剑波,坐标江苏省南通市崇川区,性格内向,希望在算法训练营与优秀的大家一起学习,也希望培养起刻意练习的习惯,持续学习。
【关于工作】:目前从事Java开发工作,主要负责公司网站群产品的功能升级和大数据产品的落地。
【工作之外】:平时骑车上班,每天大约20公里,有时候看看书,有时候看看电影,喜欢纪录频道。
【想跟你分享】:如果给我10分钟,我希望跟同学们分享关于我职业发展中的一些思考。
50 changes: 50 additions & 0 deletions Week_01/id_38/LeetCode_15_038.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.*;

/*
* @lc app=leetcode.cn id=15 lang=java
*
* [15] 三数之和
* 要点1:答案中不包含重复的三元组
*/
class LeetCode_15_038 {
public List<List<Integer>> threeSum(int[] nums) {
if (nums.length < 3) return null;
Arrays.sort(nums);

List<List<Integer>> result = new ArrayList<>();

if (nums[0] <= 0 && nums[nums.length - 1] >= 0) {
for (int i = 0; i < nums.length - 2; ++i) {
if (i > 0 && nums[i-1] == nums[i]) continue;

int l = i +1, r = nums.length - 1;
while(l < r){
if(nums[r] > -nums[i]-nums[l]){
while(l < r && nums[r-1] == nums[r]) r--;
r--;
}
else if(nums[r] < -nums[i]-nums[l]){
while(l < r && nums[l+1] == nums[l]) l++;
l++;
}
else{
result.add(Arrays.asList(nums[i],nums[l],nums[r]));
while(l < r && nums[r-1] == nums[r]) r--;
while(l < r && nums[l+1] == nums[l]) l++;
r--;
l++;
}
}
}
}

return result;
}

public static void main(String[] args) {
LeetCode_15_038 testCode_15_038 = new LeetCode_15_038();
int[] nums = new int[]{-1,0,1,2,-1,-4};
System.out.println(testCode_15_038.threeSum(nums));
}
}

30 changes: 30 additions & 0 deletions Week_01/id_38/LeetCode_242_038.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* @lc app=leetcode.cn id=242 lang=java
*
* [242] 有效的字母异位词
* 要点1:答案中不包含重复的三元组
*/
class LeetCode_242_038 {

public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) return false;

int[] hash = new int[26];
for(int i = 0; i < s.length(); ++i) {
hash[s.charAt(i) - 'a']++;
hash[t.charAt(i) - 'a']--;
}

for (int i = 0; i < hash.length; ++i) {
if (hash[i] != 0) return false;
}

return true;
}

public static void main(String[] args) {
LeetCode_242_038 testCode_242_038 = new LeetCode_242_038();
System.out.println(testCode_242_038.isAnagram("aaab", "baaa"));
}
}

37 changes: 37 additions & 0 deletions Week_01/id_38/LeetCode_26_038.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* @lc app=leetcode.cn id=26 lang=java
*
* [26] 删除排序数组中的重复项
* 要点1:有序数组
* 要点2:原地删除
*/
class LeetCode_26_038 {

/**
* 时间复杂度:O(n)
* 空间复杂度:不需要额外空间
* @param nums
* @return
*/
public int removeDuplicates(int[] nums) {
// check valid
if (nums.length == 0) return 0;

// process
int i = 0;
for (int j = 1; j < nums.length; ++j){
if (nums[i] != nums[j]) {
i++;
nums[i] = nums[j];
}
}
return i + 1;
}

public static void main(String[] args) {
LeetCode_26_038 testCode_26_038 = new LeetCode_26_038();
int[] nums = new int[]{1, 1, 2, 2, 4, 5, 7};
System.out.println(testCode_26_038.removeDuplicates(nums));
}
}

24 changes: 24 additions & 0 deletions Week_01/id_38/LeetCode_50_038.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* @lc app=leetcode.cn id=50 lang=java
*
* [50] Pow(x, n)
*/
class LeetCode_50_038 {
public double myPow(double x, int n) {
if (n == 0) return 1.0;

double half = myPow(x, n / 2);
if (n % 2 == 0) {
return half * half;
} else {
return half * half * x;
}

}

public static void main(String[] args) {
LeetCode_50_038 testCode_50_038 = new LeetCode_50_038();
System.out.println(testCode_50_038.myPow(2, 10));
}
}

65 changes: 65 additions & 0 deletions Week_01/id_38/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 学习笔记

## 第一周题目
---
### 数组、链表
<font color="green">【简单】</font>[26. 删除排序数组中的重复项 ](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/)

<font color=green>【简单】</font>[189. 旋转数组](https://leetcode-cn.com/problems/rotate-array/)

<font color=green>【简单】</font>[21. 合并两个有序链表](https://leetcode-cn.com/problems/merge-two-sorted-lists/)

<font color=green>【简单】</font>[88. 合并两个有序数组](https://leetcode-cn.com/problems/merge-sorted-array/)

<font color=orange>【中等】</font>[24. 两两交换链表中的节点](https://leetcode-cn.com/problems/swap-nodes-in-pairs/)

<font color=orange>【中等】</font>[15. 三数之和](https://leetcode-cn.com/problems/3sum/)

---

### Map & Set
[242. 有效的字母异位词<font color=green>【简单】</font>](https://leetcode-cn.com/problems/valid-anagram/)

[49. 字母异位词分组<font color=orange>【中等】</font>](https://leetcode-cn.com/problems/group-anagrams/)

---

### 堆栈、队列

[1047. 删除字符串中的所有相邻重复项<font color=green>【简单】</font>](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/)

[1021. 删除最外层的括号<font color=green>【简单】</font>](https://leetcode-cn.com/problems/remove-outermost-parentheses/)

[84. 柱状图中最大的矩形<font color=red>【困难】</font>](https://leetcode.com/problems/largest-rectangle-in-histogram/)

[42. 接雨水<font color=red>【困难】</font>](https://leetcode.com/problems/trapping-rain-water/)

---

### 二分查找

[441. 排列硬币<font color=green>【简单】</font>](https://leetcode-cn.com/problems/arranging-coins/)

[50. Pow(x, n)<font color=orange>【中等】</font>](https://leetcode-cn.com/problems/powx-n/)

[174. 地下城游戏<font color=red>【困难】</font>](https://leetcode-cn.com/problems/dungeon-game/)


---

### 递归

[104. 二叉树的最大深度<font color=green>【简单】</font>](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/)

[101. 对称二叉树<font color=green>【简单】</font>](https://leetcode-cn.com/problems/symmetric-tree/)

[111. 二叉树的最小深度<font color=green>【简单】</font>](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/)

[783. 二叉搜索树结点最小距离<font color=green>【简单】</font>](https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/)

[257. 二叉树的所有路径<font color=green>【简单】</font>](https://leetcode-cn.com/problems/binary-tree-paths/)

[938. 二叉搜索树的范围和<font color=green>【简单】</font>](https://leetcode-cn.com/problems/range-sum-of-bst/)

[236. 二叉树的最近公共祖先<font color=orange>【中等】</font>](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/)

Binary file added Week_01/id_38/数据结构与算法总结.xmind
Binary file not shown.