Skip to content

udpate #1

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/donate.png
281 changes: 146 additions & 135 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions note/001/README.md → note/0001/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class Solution {
int len = nums.length;
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < len; ++i) {
if (map.containsKey(nums[i])) {
return new int[]{map.get(nums[i]), i};
final Integer value = map.get(nums[i]);
if (value != null) {
return new int[] { value, i };
}
map.put(target - nums[i], i);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
6 changes: 3 additions & 3 deletions note/005/README.md → note/0005/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Given a string **s**, find the longest palindromic substring in **s**. You may assume that the maximum length of **s** is 1000.

**Example:**
**Example 1:**

```
Input: "babad"
Expand All @@ -14,15 +14,15 @@ Output: "bab"
Note: "aba" is also a valid answer.
```

**Example:**
**Example 2:**

```
Input: "cbbd"

Output: "bb"
```

**Tags:** String
**Tags:** String, Dynamic Programming


## 思路 0
Expand Down
22 changes: 20 additions & 2 deletions note/006/README.md → note/0006/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,28 @@ And then read line by line: `"PAHNAPLSIIGYIR"`
Write the code that will take a string and make this conversion given a number of rows:

```
string convert(string text, int nRows);
string convert(string s, int numRows);
```

`convert("PAYPALISHIRING", 3)` should return `"PAHNAPLSIIGYIR"`.
**Example 1:**

```
Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
```

**Example 2:**

```
Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:

P I N
A L S I G
Y A H R
P I
```

**Tags:** String

Expand Down
File renamed without changes.
66 changes: 53 additions & 13 deletions note/008/README.md → note/0008/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,62 @@

## Description

Implement atoi to convert a string to an integer.
Implement `atoi` which converts a string to an integer.

**Hint:** Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.

**Notes:** It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front.
The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

**Spoilers:**
If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

**Requirements for atoi:**
If no valid conversion could be performed, a zero value is returned.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
**Note:**

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.
- Only the space character `' '` is considered as whitespace character.
- Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2<sup>31</sup>, 2<sup>31</sup> − 1]. If the numerical value is out of the range of representable values, INT_MAX (2<sup>31</sup> − 1) or INT_MIN (−2<sup>31</sup>) is returned.

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
**Example 1:**

```
Input: "42"
Output: 42
```

**Example 2:**

```
Input: " -42"
Output: -42
Explanation: The first non-whitespace character is '-', which is the minus sign.
Then take as many numerical digits as possible, which gets 42.
```

**Example 3:**

```
Input: "4193 with words"
Output: 4193
Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.
```

**Example 4:**

If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned.
```
Input: "words and 987"
Output: 0
Explanation: The first non-whitespace character is 'w', which is not a numerical
digit or a +/- sign. Therefore no valid conversion could be performed.
```

**Example 5:**

```
Input: "-91283472332"
Output: -2147483648
Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer.
Thefore INT_MIN (−2^31) is returned.
```

**Tags:** Math, String

Expand All @@ -37,12 +76,13 @@ class Solution {
}
for (; i < len; ++i) {
int tmp = str.charAt(i) - '0';
if (tmp < 0 || tmp > 9)
break;
if (ans > Integer.MAX_VALUE / 10 || ans == Integer.MAX_VALUE / 10 && Integer.MAX_VALUE % 10 < tmp)
if (tmp < 0 || tmp > 9) break;
if (ans > Integer.MAX_VALUE / 10
|| (ans == Integer.MAX_VALUE / 10 && (sign == 1 && tmp > 7 || sign == -1 && tmp > 8))) {
return sign == 1 ? Integer.MAX_VALUE : Integer.MIN_VALUE;
else
} else {
ans = ans * 10 + tmp;
}
}
return sign * ans;
}
Expand Down
29 changes: 22 additions & 7 deletions note/009/README.md → note/0009/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@

## Description

Determine whether an integer is a palindrome. Do this without extra space.
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

**Spoilers:**
**Example 1:**

**Some hints:**
```
Input: 121
Output: true
```

**Example 2:**

```
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
```

Could negative integers be palindromes? (ie, -1)
**Example 3:**

If you are thinking of converting the integer to string, note the restriction of using extra space.
```
Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
```

You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case?
**Follow up:**

There is a more generic way of solving this problem.
Coud you solve it without converting the integer to a string?

**Tags:** Math

Expand Down
66 changes: 54 additions & 12 deletions note/010/README.md → note/0010/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,67 @@

## Description

Implement regular expression matching with support for `'.'` and `'*'`.
Given an input string (`s`) and a pattern (`p`), implement regular expression matching with support for `'.'` and `'*'`.

```
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
```

The matching should cover the **entire** input string (not partial).

**Note:**

- `s` could be empty and contains only lowercase letters `a-z`.
- `p` could be empty and contains only lowercase letters `a-z`, and characters like `.` or `*`.

**Example 1:**

```
Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".
```

**Example 2:**

```
Input:
s = "aa"
p = "a*"
Output: true
Explanation: '*' means zero or more of the precedeng element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
```

**Example 3:**

```
Input:
s = "ab"
p = ".*"
Output: true
Explanation: ".*" means "zero or more (*) of any character (.)".
```

The matching should cover the entire input string (not partial).
**Example 4:**

The function prototype should be:
bool isMatch(const char *s, const char *p)
```
Input:
s = "aab"
p = "c*a*b"
Output: true
Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore it matches "aab".
```

Some examples:
isMatch("aa", "a") → false
isMatch("aa", "aa") → true
isMatch("aaa", "aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true
**Example 5:**

```
Input:
s = "mississippi"
p = "mis*is*p*."
Output: false
```

**Tags:** String, Dynamic Programming, Backtracking
Expand Down
File renamed without changes.
File renamed without changes
60 changes: 58 additions & 2 deletions note/012/README.md → note/0012/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,65 @@

## Description

Given an integer, convert it to a roman numeral.
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.

Input is guaranteed to be within the range from 1 to 3999.
```
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
```

For example, two is written as `II` in Roman numeral, just two one's added together. Twelve is written as, `XII`, which is simply `X` + `II`. The number twenty seven is written as `XXVII`, which is `XX` + `V` + `II`.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:

- `I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
- `X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
- `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.

**Example 1:**

```
Input: 3
Output: "III"
```

**Example 2:**

```
Input: 4
Output: "IV"
```

**Example 3:**

```
Input: 9
Output: "IX"
```

**Example 4:**

```
Input: 58
Output: "LVIII"
Explanation: C = 100, L = 50, XXX = 30 and III = 3.
```

**Example 5:**

```
Input: 1994
Output: "MCMXCIV"
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
```

**Tags:** Math, String

Expand Down
Loading