Skip to content

[pull] main from doocs:main #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ee7ddb9
feat: add solutions to lc problems: No.3151~3153 (#2838)
yanglbme May 19, 2024
3f6a34f
feat: add solutions to lc problem: No.3154 (#2842)
yanglbme May 19, 2024
51b984f
feat: add cpp solution to lc problem: No.3068 (#2839)
AlleyNawaz May 19, 2024
f55b0d7
feat: add cpp solution to lc problem: No.3068 (#2840)
AlleyNawaz May 19, 2024
ac3102d
feat: add cpp solution to lc problem: No.3068 (#2841)
AlleyNawaz May 19, 2024
818daa9
feat: add solutions to lc problem: No.3155 (#2843)
yanglbme May 19, 2024
06533ad
feat: add solutions to lc problem: No.1317 (#2844)
yanglbme May 19, 2024
41ebef4
refactor: update solution with sorting via object to lc problem: No.2…
rain84 May 20, 2024
aa8ed86
refactor: update solution to lc problem: No.2625 (#2848)
rain84 May 20, 2024
dfb0297
feat: add ts solution to lc problem: No.1542 (#2850)
yanglbme May 20, 2024
5e67f9f
feat: update solutions to lc problem: No.2705 (#2851)
yanglbme May 20, 2024
5301c76
feat: update lc problems (#2852)
yanglbme May 20, 2024
4db3cd4
feat: add swift implementation to lcof problem: No.06 (#2853)
klever34 May 20, 2024
d2ee6aa
feat: add swift implementation to lcof problem: No.07 (#2854)
klever34 May 20, 2024
5cc6315
feat: add swift implementation to lcof problem: No.09 (#2855)
klever34 May 20, 2024
d451882
feat: add swift implementation to lcof problem: No.10.1 (#2856)
klever34 May 20, 2024
98beaf4
feat: add swift implementation to lcof problem: No.10.2 (#2857)
klever34 May 20, 2024
5f6a3af
feat: add swift implementation to lcof problem: No.11 (#2858)
klever34 May 20, 2024
df9bd5d
feat: add sql solution to lc problem: No.3156 (#2859)
yanglbme May 20, 2024
14c8085
feat: add solutions to lcp problem: No.80 (#2860)
yanglbme May 20, 2024
feae0f6
feat: update solutions to lc/lcof problems (#2861)
yanglbme May 21, 2024
27036e8
feat: update solutions to lcof problem: No.15 (#2862)
yanglbme May 21, 2024
6bb333d
--- (#2863)
dependabot[bot] May 21, 2024
a9caf56
feat: add swift implementation to lcof problem: No.12 (#2864)
klever34 May 21, 2024
d449a8a
feat: add swift implementation to lcof problem: No.13 (#2865)
klever34 May 21, 2024
7796a59
feat: add swift implementation to lcof problem: No.14.1 (#2866)
klever34 May 21, 2024
fc09c8c
feat: add swift implementation to lcof problem: No.14.2 (#2867)
klever34 May 21, 2024
d6c9b4f
feat: add swift implementation to lcof problem: No.15 (#2868)
klever34 May 21, 2024
c954041
feat: add swift implementation to lcof problem: No.16 (#2869)
klever34 May 21, 2024
3c5c2d6
feat: add solutions to lc problem: No.2831 (#2870)
yanglbme May 21, 2024
3768553
feat: update solutions to lcof problems: No.26,27,30 (#2871)
yanglbme May 21, 2024
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
3 changes: 0 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ on:
push:
branches:
- main
- docs
paths:
- package.json
- requirements.txt
- solution/**
- lcs/**
- lcp/**
Expand Down
99 changes: 65 additions & 34 deletions lcof/面试题06. 从尾到头打印链表/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ class Solution {
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
if (!head) return {};
vector<int> ans = reversePrint(head->next);
ans.push_back(head->val);
vector<int> ans;
for (; head; head = head->next) {
ans.push_back(head->val);
}
reverse(ans.begin(), ans.end());
return ans;
}
};
Expand Down Expand Up @@ -145,11 +147,11 @@ func reversePrint(head *ListNode) (ans []int) {
*/

function reversePrint(head: ListNode | null): number[] {
let ans: number[] = [];
for (; !!head; head = head.next) {
ans.unshift(head.val);
const ans: number[] = [];
for (; head; head = head.next) {
ans.push(head.val);
}
return ans;
return ans.reverse();
}
```

Expand All @@ -174,14 +176,14 @@ function reversePrint(head: ListNode | null): number[] {
// }
impl Solution {
pub fn reverse_print(head: Option<Box<ListNode>>) -> Vec<i32> {
let mut arr: Vec<i32> = vec![];
let mut ans: Vec<i32> = vec![];
let mut cur = head;
while let Some(node) = cur {
arr.push(node.val);
ans.push(node.val);
cur = node.next;
}
arr.reverse();
arr
ans.reverse();
ans
}
}
```
Expand All @@ -191,21 +193,21 @@ impl Solution {
```js
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {number[]}
*/
var reversePrint = function (head) {
let ans = [];
for (; !!head; head = head.next) {
ans.unshift(head.val);
const ans = [];
for (; head; head = head.next) {
ans.push(head.val);
}
return ans;
return ans.reverse();
};
```

Expand All @@ -217,20 +219,49 @@ var reversePrint = function (head) {
* public class ListNode {
* public int val;
* public ListNode next;
* public ListNode(int x) { val = x; }
* public ListNode(int val=0, ListNode next=null) {
* this.val = val;
* this.next = next;
* }
* }
*/
public class Solution {
public int[] ReversePrint(ListNode head) {
List<int> ans = new List<int>();
while (head != null) {
ans.Add(head.val);
head = head.next;
}
ans.Reverse();
return ans.ToArray();
}
}
public class Solution {
public int[] ReversePrint(ListNode head) {
List<int> ans = new List<int>();
for (; head != null; head = head.next) {
ans.Add(head.val);
}
ans.Reverse();
return ans.ToArray();
}
}
```

#### Swift

```swift
/* public class ListNode {
* public var val: Int
* public var next: ListNode?
* public init(_ val: Int) {
* self.val = val
* self.next = nil
* }
* }
*/

class Solution {
func reversePrint(_ head: ListNode?) -> [Int] {
var stack = [Int]()
var current = head
while let node = current {
stack.append(node.val)
current = node.next
}

return stack.reversed()
}
}
```

<!-- tabs:end -->
Expand Down Expand Up @@ -308,11 +339,11 @@ class Solution {
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int> ans;
for (; head; head = head->next) {
ans.push_back(head->val);
if (!head) {
return {};
}
reverse(ans.begin(), ans.end());
vector<int> ans = reversePrint(head->next);
ans.push_back(head->val);
return ans;
}
};
Expand Down
8 changes: 5 additions & 3 deletions lcof/面试题06. 从尾到头打印链表/Solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
if (!head) return {};
vector<int> ans = reversePrint(head->next);
ans.push_back(head->val);
vector<int> ans;
for (; head; head = head->next) {
ans.push_back(head->val);
}
reverse(ans.begin(), ans.end());
return ans;
}
};
26 changes: 14 additions & 12 deletions lcof/面试题06. 从尾到头打印链表/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
* public class ListNode {
* public int val;
* public ListNode next;
* public ListNode(int x) { val = x; }
* public ListNode(int val=0, ListNode next=null) {
* this.val = val;
* this.next = next;
* }
* }
*/
public class Solution {
public int[] ReversePrint(ListNode head) {
List<int> ans = new List<int>();
while (head != null) {
ans.Add(head.val);
head = head.next;
}
ans.Reverse();
return ans.ToArray();
}
}
public class Solution {
public int[] ReversePrint(ListNode head) {
List<int> ans = new List<int>();
for (; head != null; head = head.next) {
ans.Add(head.val);
}
ans.Reverse();
return ans.ToArray();
}
}
14 changes: 7 additions & 7 deletions lcof/面试题06. 从尾到头打印链表/Solution.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {number[]}
*/
var reversePrint = function (head) {
let ans = [];
for (; !!head; head = head.next) {
ans.unshift(head.val);
const ans = [];
for (; head; head = head.next) {
ans.push(head.val);
}
return ans;
return ans.reverse();
};
8 changes: 4 additions & 4 deletions lcof/面试题06. 从尾到头打印链表/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
// }
impl Solution {
pub fn reverse_print(head: Option<Box<ListNode>>) -> Vec<i32> {
let mut arr: Vec<i32> = vec![];
let mut ans: Vec<i32> = vec![];
let mut cur = head;
while let Some(node) = cur {
arr.push(node.val);
ans.push(node.val);
cur = node.next;
}
arr.reverse();
arr
ans.reverse();
ans
}
}
22 changes: 22 additions & 0 deletions lcof/面试题06. 从尾到头打印链表/Solution.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* public class ListNode {
* public var val: Int
* public var next: ListNode?
* public init(_ val: Int) {
* self.val = val
* self.next = nil
* }
* }
*/

class Solution {
func reversePrint(_ head: ListNode?) -> [Int] {
var stack = [Int]()
var current = head
while let node = current {
stack.append(node.val)
current = node.next
}

return stack.reversed()
}
}
8 changes: 4 additions & 4 deletions lcof/面试题06. 从尾到头打印链表/Solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/

function reversePrint(head: ListNode | null): number[] {
let ans: number[] = [];
for (; !!head; head = head.next) {
ans.unshift(head.val);
const ans: number[] = [];
for (; head; head = head.next) {
ans.push(head.val);
}
return ans;
return ans.reverse();
}
8 changes: 4 additions & 4 deletions lcof/面试题06. 从尾到头打印链表/Solution2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int> ans;
for (; head; head = head->next) {
ans.push_back(head->val);
if (!head) {
return {};
}
reverse(ans.begin(), ans.end());
vector<int> ans = reversePrint(head->next);
ans.push_back(head->val);
return ans;
}
};
44 changes: 44 additions & 0 deletions lcof/面试题07. 重建二叉树/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,50 @@ public class Solution {
}
```

#### Swift

```swift
/* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
* }
* }
*/

class Solution {
private var d = [Int: Int]()
private var preorder: [Int] = []
private var inorder: [Int] = []

func buildTree(_ preorder: [Int], _ inorder: [Int]) -> TreeNode? {
let n = inorder.count
for i in 0..<n {
d[inorder[i]] = i
}
self.preorder = preorder
self.inorder = inorder
return dfs(0, 0, n)
}

private func dfs(_ i: Int, _ j: Int, _ n: Int) -> TreeNode? {
if n < 1 {
return nil
}
let k = d[preorder[i]]!
let l = k - j
let root = TreeNode(preorder[i])
root.left = dfs(i + 1, j, l)
root.right = dfs(i + 1 + l, k + 1, n - l - 1)
return root
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Loading