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 86fc9b7

Browse files
Added Solution for 900-1000q/1064 900-1000q/1065
1 parent 48fc33d commit 86fc9b7

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

‎900-1000q/1064.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
Given an array A of distinct integers sorted in ascending order, return the smallest index i that satisfies A[i] == i. Return -1 if no such i exists.
3+
4+
5+
6+
Example 1:
7+
8+
Input: [-10,-5,0,3,7]
9+
Output: 3
10+
Explanation:
11+
For the given array, A[0] = -10, A[1] = -5, A[2] = 0, A[3] = 3, thus the output is 3.
12+
Example 2:
13+
14+
Input: [0,2,5,8,17]
15+
Output: 0
16+
Explanation:
17+
A[0] = 0, thus the output is 0.
18+
Example 3:
19+
20+
Input: [-10,-5,3,4,7,9]
21+
Output: -1
22+
Explanation:
23+
There is no such i that A[i] = i, thus the output is -1.
24+
'''
25+
26+
class Solution(object):
27+
def fixedPoint(self, A):
28+
"""
29+
:type A: List[int]
30+
:rtype: int
31+
"""
32+
if not A:
33+
return -1
34+
for index, num in enumerate(A):
35+
if num == index:
36+
return index
37+
return -1

‎900-1000q/1065.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'''
2+
Given a text string and words (a list of strings), return all index pairs [i, j] so that the substring text[i]...text[j] is in the list of words.
3+
4+
5+
6+
Example 1:
7+
8+
Input: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"]
9+
Output: [[3,7],[9,13],[10,17]]
10+
Example 2:
11+
12+
Input: text = "ababa", words = ["aba","ab"]
13+
Output: [[0,1],[0,2],[2,3],[2,4]]
14+
Explanation:
15+
Notice that matches can overlap, see "aba" is found in [0,2] and [2,4].
16+
17+
18+
Note:
19+
20+
All strings contains only lowercase English letters.
21+
It's guaranteed that all strings in words are different.
22+
1 <= text.length <= 100
23+
1 <= words.length <= 20
24+
1 <= words[i].length <= 50
25+
Return the pairs [i,j] in sorted order (i.e. sort them by their first coordinate in case of ties sort them by their second coordinate).
26+
'''
27+
28+
class Solution(object):
29+
def indexPairs(self, text, words):
30+
"""
31+
:type text: str
32+
:type words: List[str]
33+
:rtype: List[List[int]]
34+
"""
35+
if not words:
36+
return []
37+
result = []
38+
for word in words:
39+
starting = [index for index in range(len(text)) if text.startswith(word, index)]
40+
for start in starting:
41+
result.append([start, start+len(word)-1])
42+
# print starting
43+
result.sort()
44+
return result
45+

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Python solution of problems from [LeetCode](https://leetcode.com/).
1515
##### [Problems 1000-1100](./1000-1100q/)
1616
| # | Title | Solution | Difficulty |
1717
|---| ----- | -------- | ---------- |
18+
|1065|[Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string)|[Python](./1000-1100q/1065.py)|Easy|
19+
|1064|[Fixed Point](https://leetcode.com/problems/fixed-point)|[Python](./1000-1100q/1064.py)|Easy|
1820
|1054|[Distant Barcodes](https://leetcode.com/problems/distant-barcodes)|[Python](./1000-1100q/1054.py)|Medium|
1921
|1053|[Previous Permutation With One Swap](https://leetcode.com/problems/previous-permutation-with-one-swap)|[Python](./1000-1100q/1053.py)|Medium|
2022
|1052|[Grumpy Bookstore Owner](https://leetcode.com/problems/grumpy-bookstore-owner)|[Python](./1000-1100q/1052.py)|Medium|

0 commit comments

Comments
(0)

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