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 1 commit
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
Prev Previous commit
Next Next commit
feat: add solutions to lc problem: No.1317 (doocs#2844)
  • Loading branch information
yanglbme authored May 19, 2024
commit 06533ad9ae3b79b240d3782c037f289e53cdaed0
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ tags:

### 方法一:直接枚举

从 $1$ 开始枚举 $a$,判断 $a$ 和 $n - a$ 是否满足条件,如果满足则返回
从 $1$ 开始枚举 $a$,那么 $b = n - a$。对于每个 $a$ 和 $b$,我们将它们转换为字符串并且连接起来,然后判断是否包含字符 `'0'`,如果不包含,那么就找到了答案,返回 $[a, b]$

时间复杂度 $O(n\times \log n)$,空间复杂度 $O(1)$。其中 $n$ 为题目给定的整数
时间复杂度 $O(n \times \log n)$,其中 $n$ 为题目给定的整数。空间复杂度 $O(\log n)$

<!-- tabs:start -->

Expand Down Expand Up @@ -141,13 +141,30 @@ func getNoZeroIntegers(n int) []int {
}
```

#### TypeScript

```ts
function getNoZeroIntegers(n: number): number[] {
for (let a = 1; ; ++a) {
const b = n - a;
if (!`${a}${b}`.includes('0')) {
return [a, b];
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- solution:start -->

### 方法二
### 方法二:直接枚举(另一种写法)

在方法一中,我们将 $a$ 和 $b$ 转换为字符串并且连接起来,然后判断是否包含字符 `'0'`。这里我们可以通过一个函数 $f(x)$ 来判断 $x$ 是否包含字符 `'0'`,然后直接枚举 $a$,判断 $a$ 和 $b = n - a$ 是否都不包含字符 `'0'`,如果是,则找到了答案,返回 $[a, b]$。

时间复杂度 $O(n \times \log n)$,其中 $n$ 为题目给定的整数。空间复杂度 $O(1)$。

<!-- tabs:start -->

Expand Down Expand Up @@ -238,6 +255,27 @@ func getNoZeroIntegers(n int) []int {
}
```

#### TypeScript

```ts
function getNoZeroIntegers(n: number): number[] {
const f = (x: number): boolean => {
for (; x; x = (x / 10) | 0) {
if (x % 10 === 0) {
return false;
}
}
return true;
};
for (let a = 1; ; ++a) {
const b = n - a;
if (f(a) && f(b)) {
return [a, b];
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ Note that there are other valid answers as [8, 3] that can be accepted.

<!-- solution:start -->

### Solution 1
### Solution 1: Direct Enumeration

Starting from $1$, we enumerate $a$, then $b = n - a$. For each $a$ and $b$, we convert them to strings and concatenate them, then check if they contain the character '0'. If they do not contain '0', we have found the answer and return $[a, b]$.

The time complexity is $O(n \times \log n)$, where $n$ is the integer given in the problem. The space complexity is $O(\log n)$.

<!-- tabs:start -->

Expand Down Expand Up @@ -121,13 +125,30 @@ func getNoZeroIntegers(n int) []int {
}
```

#### TypeScript

```ts
function getNoZeroIntegers(n: number): number[] {
for (let a = 1; ; ++a) {
const b = n - a;
if (!`${a}${b}`.includes('0')) {
return [a, b];
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- solution:start -->

### Solution 2
### Solution 2: Direct Enumeration (Alternative Approach)

In Solution 1, we converted $a$ and $b$ into strings and concatenated them, then checked if they contained the character '0'. Here, we can use a function $f(x)$ to check whether $x$ contains the character '0', and then directly enumerate $a$, checking whether both $a$ and $b = n - a$ do not contain the character '0'. If they do not, we have found the answer and return $[a, b]$.

The time complexity is $O(n \times \log n)$, where $n$ is the integer given in the problem. The space complexity is $O(1)$.

<!-- tabs:start -->

Expand Down Expand Up @@ -218,6 +239,27 @@ func getNoZeroIntegers(n int) []int {
}
```

#### TypeScript

```ts
function getNoZeroIntegers(n: number): number[] {
const f = (x: number): boolean => {
for (; x; x = (x / 10) | 0) {
if (x % 10 === 0) {
return false;
}
}
return true;
};
for (let a = 1; ; ++a) {
const b = n - a;
if (f(a) && f(b)) {
return [a, b];
}
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function getNoZeroIntegers(n: number): number[] {
for (let a = 1; ; ++a) {
const b = n - a;
if (!`${a}${b}`.includes('0')) {
return [a, b];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function getNoZeroIntegers(n: number): number[] {
const f = (x: number): boolean => {
for (; x; x = (x / 10) | 0) {
if (x % 10 === 0) {
return false;
}
}
return true;
};
for (let a = 1; ; ++a) {
const b = n - a;
if (f(a) && f(b)) {
return [a, b];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ tags:
```cpp
class Solution {
public:
long long maximumValueSum(vector<int>& nums, int k,
vector<vector<int>>& edges) {
long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {
long long totalSum = 0;
int count = 0;
int positiveMin = INT_MAX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ It can be shown that 9 is the maximum achievable sum of values.
```cpp
class Solution {
public:
long long maximumValueSum(vector<int>& nums, int k,
vector<vector<int>>& edges) {
long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {
long long totalSum = 0;
int count = 0;
int positiveMin = INT_MAX;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Solution {
public:
long long maximumValueSum(vector<int>& nums, int k,
vector<vector<int>>& edges) {
long long maximumValueSum(vector<int>& nums, int k, vector<vector<int>>& edges) {
long long totalSum = 0;
int count = 0;
int positiveMin = INT_MAX;
Expand Down