Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 091c879

Browse files
author
Sandy
authored
Merge pull request #7 from openset/develop
Add: README
2 parents af85cd9 + a307180 commit 091c879

File tree

10 files changed

+289
-4
lines changed

10 files changed

+289
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## 14. Longest Common Prefix
2+
3+
Write a function to find the longest common prefix string amongst an array of strings.
4+
5+
If there is no common prefix, return an empty string "".
6+
7+
**Example 1:**
8+
```text
9+
Input: ["flower","flow","flight"]
10+
Output: "fl"
11+
```
12+
13+
**Example 2:**
14+
```text
15+
Input: ["dog","racecar","car"]
16+
Output: ""
17+
Explanation: There is no common prefix among the input strings.
18+
```
19+
20+
**Note:**
21+
22+
All given inputs are in lowercase letters `a-z`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 21. Merge Two Sorted Lists
2+
3+
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
4+
5+
**Example:**
6+
```text
7+
Input: 1->2->4, 1->3->4
8+
Output: 1->1->2->3->4->4
9+
```

‎solution/palindrome-number/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## 9. Palindrome Number
2+
3+
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
4+
5+
**Example 1:**
6+
```text
7+
Input: 121
8+
Output: true
9+
```
10+
11+
**Example 2:**
12+
```text
13+
Input: -121
14+
Output: false
15+
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
16+
```
17+
18+
**Example 3:**
19+
```text
20+
Input: 10
21+
Output: false
22+
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
23+
```
24+
25+
**Follow up:**
26+
27+
Coud you solve it without converting the integer to a string?
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## 26. Remove Duplicates from Sorted Array
2+
3+
Given a sorted array nums, remove the duplicates `in-place` such that each element appear only once and return the new length.
4+
5+
Do not allocate extra space for another array, you must do this by `modifying the input array` `in-place` with O(1) extra memory.
6+
7+
**Example 1:**
8+
```text
9+
Given nums = [1,1,2],
10+
11+
Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively.
12+
13+
It doesn't matter what you leave beyond the returned length.
14+
```
15+
16+
**Example 2:**
17+
```text
18+
Given nums = [0,0,1,1,1,2,2,3,3,4],
19+
20+
Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively.
21+
22+
It doesn't matter what values are set beyond the returned length.
23+
```
24+
25+
**Clarification:**
26+
27+
Confused why the returned value is an integer but your answer is an array?
28+
29+
Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.
30+
31+
Internally you can think of this:
32+
```text
33+
// nums is passed in by reference. (i.e., without making a copy)
34+
int len = removeDuplicates(nums);
35+
36+
// any modification to nums in your function would be known by the caller.
37+
// using the length returned by your function, it prints the first len elements.
38+
for (int i = 0; i < len; i++) {
39+
print(nums[i]);
40+
}
41+
```

‎solution/remove-element/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ Do not allocate extra space for another array, you must do this by `modifying th
77
The order of elements can be changed. It doesn't matter what you leave beyond the new length.
88

99
**Example 1:**
10-
```
10+
```text
1111
Given nums = [3,2,2,3], val = 3,
1212
1313
Your function should return length = 2, with the first two elements of nums being 2.
1414
1515
It doesn't matter what you leave beyond the returned length.
1616
```
17-
**Example 2:**
1817

19-
```
18+
**Example 2:**
19+
```text
2020
Given nums = [0,1,2,2,3,0,4,2], val = 2,
2121
2222
Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4.
@@ -25,6 +25,7 @@ Note that the order of those five elements can be arbitrary.
2525
2626
It doesn't matter what values are set beyond the returned length.
2727
```
28+
2829
**Clarification:**
2930

3031
Confused why the returned value is an integer but your answer is an array?
@@ -33,7 +34,7 @@ Note that the input array is passed in by reference, which means modification to
3334

3435
Internally you can think of this:
3536

36-
```
37+
```text
3738
// nums is passed in by reference. (i.e., without making a copy)
3839
int len = removeElement(nums, val);
3940

‎solution/reverse-integer/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## 7. Reverse Integer
2+
3+
Given a 32-bit signed integer, reverse digits of an integer.
4+
5+
**Example 1:**
6+
```text
7+
Input: 123
8+
Output: 321
9+
```
10+
11+
**Example 2:**
12+
```text
13+
Input: -123
14+
Output: -321
15+
```
16+
17+
**Example 3:**
18+
```text
19+
Input: 120
20+
Output: 21
21+
```
22+
23+
**Note:**
24+
25+
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

‎solution/roman-to-integer/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## 13. Roman to Integer
2+
3+
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
4+
```text
5+
Symbol Value
6+
I 1
7+
V 5
8+
X 10
9+
L 50
10+
C 100
11+
D 500
12+
M 1000
13+
```
14+
15+
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`.
16+
17+
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:
18+
19+
- `I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
20+
- `X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
21+
- `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
22+
23+
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.
24+
25+
**Example 1:**
26+
```text
27+
Input: "III"
28+
Output: 3
29+
```
30+
31+
**Example 2:**
32+
```text
33+
Input: "IV"
34+
Output: 4
35+
```
36+
37+
**Example 3:**
38+
```text
39+
Input: "IX"
40+
Output: 9
41+
```
42+
43+
**Example 4:**
44+
```text
45+
Input: "LVIII"
46+
Output: 58
47+
Explanation: L = 50, V= 5, III = 3.
48+
```
49+
50+
**Example 5:**
51+
```text
52+
Input: "MCMXCIV"
53+
Output: 1994
54+
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
55+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## 8. String to Integer (atoi)
2+
3+
Implement `atoi` which converts a string to an integer.
4+
5+
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.
6+
7+
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.
8+
9+
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.
10+
11+
If no valid conversion could be performed, a zero value is returned.
12+
13+
**Note:**
14+
- Only the space character ' ' is considered as whitespace character.
15+
- Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
16+
17+
**Example 1:**
18+
```text
19+
Input: "42"
20+
Output: 42
21+
```
22+
23+
**Example 2:**
24+
```text
25+
Input: " -42"
26+
Output: -42
27+
Explanation: The first non-whitespace character is '-', which is the minus sign.
28+
Then take as many numerical digits as possible, which gets 42.
29+
```
30+
31+
**Example 3:**
32+
```text
33+
Input: "4193 with words"
34+
Output: 4193
35+
Explanation: Conversion stops at digit '3' as the next character is not a numerical digit.
36+
```
37+
38+
**Example 4:**
39+
```text
40+
Input: "words and 987"
41+
Output: 0
42+
Explanation: The first non-whitespace character is 'w', which is not a numerical
43+
digit or a +/- sign. Therefore no valid conversion could be performed.
44+
```
45+
46+
**Example 5:**
47+
```text
48+
Input: "-91283472332"
49+
Output: -2147483648
50+
Explanation: The number "-91283472332" is out of the range of a 32-bit signed integer.
51+
Thefore INT_MIN (−231) is returned.
52+
```

‎solution/two-sum/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## 1. Two Sum
2+
3+
Given an array of integers, return `indices` of the two numbers such that they add up to a specific target.
4+
5+
You may assume that each input would have `exactly` one solution, and you may not use the same element twice.
6+
7+
**Example:**
8+
9+
```text
10+
Given nums = [2, 7, 11, 15], target = 9,
11+
12+
Because nums[0] + nums[1] = 2 + 7 = 9,
13+
return [0, 1].
14+
```

‎solution/valid-parentheses/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## 20. Valid Parentheses
2+
3+
Given a string containing just the characters `'('`, `')'`, `'{'`, `'}'`, `'['` and `']'`, determine if the input string is valid.
4+
5+
An input string is valid if:
6+
1. Open brackets must be closed by the same type of brackets.
7+
1. Open brackets must be closed in the correct order.
8+
9+
Note that an empty string is also considered valid.
10+
11+
**Example 1:**
12+
```text
13+
Input: "()"
14+
Output: true
15+
```
16+
17+
**Example 2:**
18+
```text
19+
Input: "()[]{}"
20+
Output: true
21+
```
22+
23+
**Example 3:**
24+
```text
25+
Input: "(]"
26+
Output: false
27+
```
28+
29+
**Example 4:**
30+
```text
31+
Input: "([)]"
32+
Output: false
33+
```
34+
35+
**Example 5:**
36+
```text
37+
Input: "{[]}"
38+
Output: true
39+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /