Skip to content

Commit 9403f58

Browse files
feat: azl397985856#19 add java implementation (azl397985856#257)
* correct typos * Add translations * 新增HTTP/1.0, HTTP/1.1, HTTP/2的对比 * 增加HTTP/1.1和HTTP/2的性能对比的Demo * 翻译大部分基础数据结构,但是REACT部分没有翻译 * update description of `HTTP/1.0` * add WIP tag, update some translation details * change 'fundamental' to 'basic' * remove some trivial details about HTTP/1.0 * error correction * translation for DP * translation for string problems * error correction * correct wrongly typed * translation for binary-tree-traversal.md * correct wrongly typed * update README.en.md * update description of Huffman encoding * update file path of Binary-tree-traversal-en.md. * correct wrongly typed * update paths of thinkings * translation for basic-algorithm.md (Draft) * translation for bloom-filter.md * add java solution with inorder traversing * Update 230.kth-smallest-element-in-a-bst.md * add java implementations. * add java implementations * Update 94.binary-tree-inorder-traversal.md * Update 98.validate-binary-search-tree.md * add java implementation to 19 * fix conflict * fix typo Co-authored-by: lucifer <[email protected]>
1 parent 947a923 commit 9403f58

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Diff for: problems/19.removeNthNodeFromEndofList.md

+37
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Could you do this in one pass?
4949

5050
## 代码
5151

52+
Support: JS, Java
53+
54+
- Javascript Implementation
5255

5356
```js
5457
/*
@@ -128,4 +131,38 @@ var removeNthFromEnd = function(head, n) {
128131
return dummyHead.next;
129132
};
130133

134+
```
135+
136+
- Java Code
137+
138+
```java
139+
/**
140+
* Definition for singly-linked list.
141+
* public class ListNode {
142+
* int val;
143+
* ListNode next;
144+
* ListNode(int x) { val = x; }
145+
* }
146+
*/
147+
class Solution {
148+
public ListNode removeNthFromEnd(ListNode head, int n) {
149+
TreeNode dummy = new TreeNode(0);
150+
dummy.next = head;
151+
TreeNode first = dummy;
152+
TreeNode second = dummy;
153+
154+
if (int i=0; i<=n; i++) {
155+
first = first.next;
156+
}
157+
158+
while (first != null) {
159+
first = first.next;
160+
second = second.next;
161+
}
162+
163+
second.next = second.next.next;
164+
165+
return dummy.next;
166+
}
167+
}
131168
```

Diff for: problems/53.maximum-sum-subarray-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ If you have figured out the O(n) solution, try coding another solution using the
8080

8181
#### 复杂度分析
8282
- *时间复杂度:* `O(nlogn) - n 是数组长度`
83-
- *空间复杂度:* `O(logn)` - 因为调用栈的深度最多是logn。
83+
- *空间复杂度:* `Ologn)` - 因为调用栈的深度最多是logn。
8484

8585
#### 解法五 - [动态规划](https://www.wikiwand.com/zh-hans/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92)
8686
动态规划的难点在于找到状态转移方程,

Diff for: problems/98.validate-binary-search-tree.md

-1
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,3 @@ class Solution {
314314
## 相关题目
315315

316316
[230.kth-smallest-element-in-a-bst](./230.kth-smallest-element-in-a-bst.md)
317-

0 commit comments

Comments
 (0)