Skip to content

Commit 6c4ee83

Browse files
committed
add my solutions
1 parent e8bfc2c commit 6c4ee83

File tree

30 files changed

+496
-46
lines changed

30 files changed

+496
-46
lines changed

README.md

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
# leetcode solutions using javascript,python,python3,c++,c
2-
This is my leetcode solution folder.
1+
<p align="center"><img width="300" src="https://raw.githubusercontent.com/Ma63d/leetcode-spider/master/img/site-logo.png"></p>
2+
<p align="center">
3+
<img src="https://img.shields.io/badge/Solved/Total(Locked)-13/573(107)-green.svg?style=flat-square" alt="">
4+
<img src="https://img.shields.io/badge/Hard-0-blue.svg?style=flat-square" alt="">
5+
<img src="https://img.shields.io/badge/Medium-5-blue.svg?style=flat-square" alt="">
6+
<img src="https://img.shields.io/badge/Easy-8-blue.svg?style=flat-square" alt="">
7+
</p>
8+
<h3 align="center">My leetcode solutions</h3>
39

4-
Language: javascript,python,python3,c++,c
10+
<p align="center">
11+
<b>Language: javascript python python3 c++ c</b>
12+
<br>
13+
<b>Last updated: 2017-07-28</b>
14+
<br><br>
15+
</p>
16+
<!--请保留下面这行信息,让更多用户了解到这个小爬虫,衷心感谢您的支持-->
17+
<p align="center">The source code is fetched using the tool <a href="https://github.com/Ma63d/leetcode-spider">leetcode-spider</a>.</p>
518

6-
Last updated: 2017-07-27
19+
| # | Problems | Solutions | Difficulty | Acceptance | Paid-Only
20+
|:--:|:-----:|:---------:|:----:|:----:|:----:|
21+
|001|[two-sum](https://leetcode.com/problems/two-sum/)| [python](.&#x2F;solutions&#x2F;001.two-sum&#x2F;two-sum.py)|Easy|34.13%||
22+
|002|[add-two-numbers](https://leetcode.com/problems/add-two-numbers/)| [c](.&#x2F;solutions&#x2F;002.add-two-numbers&#x2F;add-two-numbers.c)|Medium|27.64%||
23+
|003|[longest-substring-without-repeating-characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [javascript](.&#x2F;solutions&#x2F;003.longest-substring-without-repeating-characters&#x2F;longest-substring-without-repeating-characters.js)|Medium|24.27%||
24+
|007|[reverse-integer](https://leetcode.com/problems/reverse-integer/)| [c](.&#x2F;solutions&#x2F;007.reverse-integer&#x2F;reverse-integer.c)|Easy|24.32%||
25+
|009|[palindrome-number](https://leetcode.com/problems/palindrome-number/)| [python](.&#x2F;solutions&#x2F;009.palindrome-number&#x2F;palindrome-number.py)|Easy|35.20%||
26+
|013|[roman-to-integer](https://leetcode.com/problems/roman-to-integer/)| [python](.&#x2F;solutions&#x2F;013.roman-to-integer&#x2F;roman-to-integer.py)|Easy|45.52%||
27+
|014|[longest-common-prefix](https://leetcode.com/problems/longest-common-prefix/)| [c++](.&#x2F;solutions&#x2F;014.longest-common-prefix&#x2F;longest-common-prefix.cpp)|Easy|31.44%||
28+
|019|[remove-nth-node-from-end-of-list](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)| [c](.&#x2F;solutions&#x2F;019.remove-nth-node-from-end-of-list&#x2F;remove-nth-node-from-end-of-list.c)|Medium|33.34%||
29+
|026|[remove-duplicates-from-sorted-array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [c](.&#x2F;solutions&#x2F;026.remove-duplicates-from-sorted-array&#x2F;remove-duplicates-from-sorted-array.c)|Easy|35.50%||
30+
|027|[remove-element](https://leetcode.com/problems/remove-element/)| [c++](.&#x2F;solutions&#x2F;027.remove-element&#x2F;remove-element.cpp)|Easy|38.84%||
31+
|035|[search-insert-position](https://leetcode.com/problems/search-insert-position/)| [c](.&#x2F;solutions&#x2F;035.search-insert-position&#x2F;search-insert-position.c)|Easy|39.66%||
32+
|056|[merge-intervals](https://leetcode.com/problems/merge-intervals/)| [javascript](.&#x2F;solutions&#x2F;056.merge-intervals&#x2F;merge-intervals.js)|Medium|29.89%||
33+
|061|[rotate-list](https://leetcode.com/problems/rotate-list/)| [c](.&#x2F;solutions&#x2F;061.rotate-list&#x2F;rotate-list.c)|Medium|24.34%||
734

8-
I've solved 13/573 problems (107 problems for a fee).
9-
10-
The source code was fetched using the tool [leetcode-spider](https://github.com/Ma63d/leetcode-spider).
11-
12-
| # | Problems | Solutions | Difficulty |
13-
|:--:|:-----:|:---------:|:----:|
14-
|001|[two-sum](https://leetcode.com/problems/two-sum/)| [python](./solutions/001.two-sum/two-sum.py)| Easy|
15-
|002|[add-two-numbers](https://leetcode.com/problems/add-two-numbers/)| [c](./solutions/002.add-two-numbers/add-two-numbers.c)| Medium|
16-
|003|[longest-substring-without-repeating-characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [javascript](./solutions/003.longest-substring-without-repeating-characters/longest-substring-without-repeating-characters.js)| Medium|
17-
|007|[reverse-integer](https://leetcode.com/problems/reverse-integer/)| [c](./solutions/007.reverse-integer/reverse-integer.c)| Easy|
18-
|009|[palindrome-number](https://leetcode.com/problems/palindrome-number/)| [python](./solutions/009.palindrome-number/palindrome-number.py)| Easy|
19-
|013|[roman-to-integer](https://leetcode.com/problems/roman-to-integer/)| [python](./solutions/013.roman-to-integer/roman-to-integer.py)| Easy|
20-
|014|[longest-common-prefix](https://leetcode.com/problems/longest-common-prefix/)| [c++](./solutions/014.longest-common-prefix/longest-common-prefix.cpp)| Easy|
21-
|019|[remove-nth-node-from-end-of-list](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)| [c](./solutions/019.remove-nth-node-from-end-of-list/remove-nth-node-from-end-of-list.c)| Medium|
22-
|026|[remove-duplicates-from-sorted-array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [c](./solutions/026.remove-duplicates-from-sorted-array/remove-duplicates-from-sorted-array.c)| Easy|
23-
|027|[remove-element](https://leetcode.com/problems/remove-element/)| [c++](./solutions/027.remove-element/remove-element.cpp)| Easy|
24-
|035|[search-insert-position](https://leetcode.com/problems/search-insert-position/)| [c](./solutions/035.search-insert-position/search-insert-position.c)| Easy|
25-
|056|[merge-intervals](https://leetcode.com/problems/merge-intervals/)| [javascript](./solutions/056.merge-intervals/merge-intervals.js)| Medium|
26-
|061|[rotate-list](https://leetcode.com/problems/rotate-list/)| [c](./solutions/061.rotate-list/rotate-list.c)| Medium|

solutions/README.md

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
# leetcode solutions using javascript,python,python3,c++,c
2-
This is my leetcode solution folder.
1+
<p align="center"><img width="300" src="https://raw.githubusercontent.com/Ma63d/leetcode-spider/master/img/site-logo.png"></p>
2+
<p align="center">
3+
<img src="https://img.shields.io/badge/Solved/Total(Locked)-13/573(107)-green.svg?style=flat-square" alt="">
4+
<img src="https://img.shields.io/badge/Hard-0-blue.svg?style=flat-square" alt="">
5+
<img src="https://img.shields.io/badge/Medium-5-blue.svg?style=flat-square" alt="">
6+
<img src="https://img.shields.io/badge/Easy-8-blue.svg?style=flat-square" alt="">
7+
</p>
8+
<h3 align="center">My leetcode solutions</h3>
39

4-
Language: javascript,python,python3,c++,c
10+
<p align="center">
11+
<b>Language: javascript python python3 c++ c</b>
12+
<br>
13+
<b>Last updated: 2017-07-28</b>
14+
<br><br>
15+
</p>
16+
<!--请保留下面这行信息,让更多用户了解到这个小爬虫,衷心感谢您的支持-->
17+
<p align="center">The source code is fetched using the tool <a href="https://github.com/Ma63d/leetcode-spider">leetcode-spider</a>.</p>
518

6-
Last updated: 2017-07-27
19+
| # | Problems | Solutions | Difficulty | Acceptance | Paid-Only
20+
|:--:|:-----:|:---------:|:----:|:----:|:----:|
21+
|001|[two-sum](https://leetcode.com/problems/two-sum/)| [python](.&#x2F;solutions&#x2F;001.two-sum&#x2F;two-sum.py)|Easy|34.13%||
22+
|002|[add-two-numbers](https://leetcode.com/problems/add-two-numbers/)| [c](.&#x2F;solutions&#x2F;002.add-two-numbers&#x2F;add-two-numbers.c)|Medium|27.64%||
23+
|003|[longest-substring-without-repeating-characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [javascript](.&#x2F;solutions&#x2F;003.longest-substring-without-repeating-characters&#x2F;longest-substring-without-repeating-characters.js)|Medium|24.27%||
24+
|007|[reverse-integer](https://leetcode.com/problems/reverse-integer/)| [c](.&#x2F;solutions&#x2F;007.reverse-integer&#x2F;reverse-integer.c)|Easy|24.32%||
25+
|009|[palindrome-number](https://leetcode.com/problems/palindrome-number/)| [python](.&#x2F;solutions&#x2F;009.palindrome-number&#x2F;palindrome-number.py)|Easy|35.20%||
26+
|013|[roman-to-integer](https://leetcode.com/problems/roman-to-integer/)| [python](.&#x2F;solutions&#x2F;013.roman-to-integer&#x2F;roman-to-integer.py)|Easy|45.52%||
27+
|014|[longest-common-prefix](https://leetcode.com/problems/longest-common-prefix/)| [c++](.&#x2F;solutions&#x2F;014.longest-common-prefix&#x2F;longest-common-prefix.cpp)|Easy|31.44%||
28+
|019|[remove-nth-node-from-end-of-list](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)| [c](.&#x2F;solutions&#x2F;019.remove-nth-node-from-end-of-list&#x2F;remove-nth-node-from-end-of-list.c)|Medium|33.34%||
29+
|026|[remove-duplicates-from-sorted-array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [c](.&#x2F;solutions&#x2F;026.remove-duplicates-from-sorted-array&#x2F;remove-duplicates-from-sorted-array.c)|Easy|35.50%||
30+
|027|[remove-element](https://leetcode.com/problems/remove-element/)| [c++](.&#x2F;solutions&#x2F;027.remove-element&#x2F;remove-element.cpp)|Easy|38.84%||
31+
|035|[search-insert-position](https://leetcode.com/problems/search-insert-position/)| [c](.&#x2F;solutions&#x2F;035.search-insert-position&#x2F;search-insert-position.c)|Easy|39.66%||
32+
|056|[merge-intervals](https://leetcode.com/problems/merge-intervals/)| [javascript](.&#x2F;solutions&#x2F;056.merge-intervals&#x2F;merge-intervals.js)|Medium|29.89%||
33+
|061|[rotate-list](https://leetcode.com/problems/rotate-list/)| [c](.&#x2F;solutions&#x2F;061.rotate-list&#x2F;rotate-list.c)|Medium|24.34%||
734

8-
I've solved 13/573 problems (107 problems for a fee).
9-
10-
The source code was fetched using the tool [leetcode-spider](https://github.com/Ma63d/leetcode-spider).
11-
12-
| # | Problems | Solutions | Difficulty |
13-
|:--:|:-----:|:---------:|:----:|
14-
|001|[two-sum](https://leetcode.com/problems/two-sum/)| [python](./solutions/001.two-sum/two-sum.py)| Easy|
15-
|002|[add-two-numbers](https://leetcode.com/problems/add-two-numbers/)| [c](./solutions/002.add-two-numbers/add-two-numbers.c)| Medium|
16-
|003|[longest-substring-without-repeating-characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/)| [javascript](./solutions/003.longest-substring-without-repeating-characters/longest-substring-without-repeating-characters.js)| Medium|
17-
|007|[reverse-integer](https://leetcode.com/problems/reverse-integer/)| [c](./solutions/007.reverse-integer/reverse-integer.c)| Easy|
18-
|009|[palindrome-number](https://leetcode.com/problems/palindrome-number/)| [python](./solutions/009.palindrome-number/palindrome-number.py)| Easy|
19-
|013|[roman-to-integer](https://leetcode.com/problems/roman-to-integer/)| [python](./solutions/013.roman-to-integer/roman-to-integer.py)| Easy|
20-
|014|[longest-common-prefix](https://leetcode.com/problems/longest-common-prefix/)| [c++](./solutions/014.longest-common-prefix/longest-common-prefix.cpp)| Easy|
21-
|019|[remove-nth-node-from-end-of-list](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)| [c](./solutions/019.remove-nth-node-from-end-of-list/remove-nth-node-from-end-of-list.c)| Medium|
22-
|026|[remove-duplicates-from-sorted-array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)| [c](./solutions/026.remove-duplicates-from-sorted-array/remove-duplicates-from-sorted-array.c)| Easy|
23-
|027|[remove-element](https://leetcode.com/problems/remove-element/)| [c++](./solutions/027.remove-element/remove-element.cpp)| Easy|
24-
|035|[search-insert-position](https://leetcode.com/problems/search-insert-position/)| [c](./solutions/035.search-insert-position/search-insert-position.c)| Easy|
25-
|056|[merge-intervals](https://leetcode.com/problems/merge-intervals/)| [javascript](./solutions/056.merge-intervals/merge-intervals.js)| Medium|
26-
|061|[rotate-list](https://leetcode.com/problems/rotate-list/)| [c](./solutions/061.rotate-list/rotate-list.c)| Medium|

solutions/README.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<p align="center"><img width="300" src="https://raw.githubusercontent.com/Ma63d/leetcode-spider/master/img/site-logo.png"></p>
2+
<p align="center">
3+
<img src="https://img.shields.io/badge/Solved/Total(Locked)-{{solved}}/{{total}}({{locked}})-green.svg?style=flat-square" alt="">
4+
<img src="https://img.shields.io/badge/Hard-{{hard}}-blue.svg?style=flat-square" alt="">
5+
<img src="https://img.shields.io/badge/Medium-{{medium}}-blue.svg?style=flat-square" alt="">
6+
<img src="https://img.shields.io/badge/Easy-{{easy}}-blue.svg?style=flat-square" alt="">
7+
</p>
8+
<h3 align="center">My leetcode solutions</h3>
9+
10+
<p align="center">
11+
<b>Language: {{language}}</b>
12+
<br>
13+
<b>Last updated: {{time}}</b>
14+
<br><br>
15+
</p>
16+
<!--请保留下面这行信息,让更多用户了解到这个小爬虫,衷心感谢您的支持-->
17+
<p align="center">The source code is fetched using the tool <a href="https://github.com/Ma63d/leetcode-spider">leetcode-spider</a>.</p>
18+
19+
| # | Problems | Solutions | Difficulty | Acceptance | Paid-Only
20+
|:--:|:-----:|:---------:|:----:|:----:|:----:|
21+
{{#solutions}}
22+
|{{id}}|[{{title}}](https://leetcode.com/problems/{{title}}/)|{{solutionLinks}}|{{difficulty}}|{{acceptance}}|{{paidOnly}}|
23+
{{/solutions}}
24+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
2+
3+
You may assume that each input would have exactly one solution, and you may not use the same element twice.
4+
5+
6+
Example:
7+
8+
Given nums = [2, 7, 11, 15], target = 9,
9+
10+
Because nums[0] + nums[1] = 2 + 7 = 9,
11+
return [0, 1].
12+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def twoSum(self, nums, target):
3+
length = len(nums)
4+
hashmap = {}
5+
for i in range(0,length):
6+
x = nums[i]
7+
if target - x in hashmap:
8+
return [hashmap[target -x], i]
9+
else:
10+
hashmap[x] = i
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* struct ListNode *next;
6+
* };
7+
*/
8+
/**
9+
* Definition for singly-linked list.
10+
* struct ListNode {
11+
* int val;
12+
* struct ListNode *next;
13+
* };
14+
*/
15+
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
16+
struct ListNode *result, *currentNode, *headNode;
17+
headNode = NULL;
18+
int flag = 0;
19+
while(l1 != NULL && l2 !=NULL) {
20+
currentNode = (struct ListNode *)malloc(sizeof(struct ListNode));
21+
currentNode->next = NULL;
22+
if(l1->val + l2->val + flag > 9) {
23+
currentNode->val = l1->val + l2->val + flag - 10;
24+
flag = 1;
25+
} else {
26+
currentNode->val = l1->val + l2->val + flag;
27+
flag = 0;
28+
}
29+
if (headNode == NULL) {
30+
headNode = currentNode;
31+
} else {
32+
result->next = currentNode;
33+
}
34+
result = currentNode;
35+
l1 = l1->next;
36+
l2 = l2->next;
37+
}
38+
while(l1 != NULL) {
39+
currentNode = (struct ListNode *)malloc(sizeof(struct ListNode));
40+
currentNode->next = NULL;
41+
if(l1->val + flag > 9){
42+
currentNode->val = l1->val + flag - 10;
43+
flag = 1;
44+
} else {
45+
currentNode->val = l1->val + flag;
46+
flag = 0;
47+
}
48+
result->next = currentNode;
49+
result = currentNode;
50+
l1 = l1->next;
51+
}
52+
while(l2 != NULL) {
53+
currentNode = (struct ListNode *)malloc(sizeof(struct ListNode));
54+
currentNode->next = NULL;
55+
if(l2->val + flag > 9){
56+
currentNode->val = l2->val + flag - 10;
57+
flag = 1;
58+
} else {
59+
currentNode->val = l2->val + flag;
60+
flag = 0;
61+
}
62+
result->next = currentNode;
63+
result = currentNode;
64+
l2 = l2->next;
65+
}
66+
if(flag != 0) {
67+
currentNode = (struct ListNode *)malloc(sizeof(struct ListNode));
68+
currentNode->next = NULL;
69+
currentNode->val = flag;
70+
result->next = currentNode;
71+
}
72+
return headNode;
73+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
2+
3+
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
4+
5+
6+
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
7+
Output: 7 -> 0 -> 8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var lengthOfLongestSubstring = function(s) {
2+
var hashmap = {};
3+
var result = 0;
4+
var left = 0;
5+
var j = left;
6+
while(j < s.length) {
7+
if (hashmap[s[j]] !== undefined) {
8+
left = Math.max(hashmap[s[j]] + 1, left);
9+
}
10+
result = Math.max(result, j - left + 1);
11+
hashmap[s[j]] = j++;
12+
}
13+
return result;
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Given a string, find the length of the longest substring without repeating characters.
2+
3+
Examples:
4+
5+
Given "abcabcbb", the answer is "abc", which the length is 3.
6+
7+
Given "bbbbb", the answer is "b", with the length of 1.
8+
9+
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Reverse digits of an integer.
2+
3+
4+
Example1: x = 123, return 321
5+
Example2: x = -123, return -321
6+
7+
8+
click to show spoilers.
9+
10+
Have you thought about this?
11+
12+
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
13+
14+
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
15+
16+
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
17+
18+
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
19+
20+
21+
22+
23+
24+
Note:
25+
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int reverse(int x) {
2+
long long reverseNum = 0;
3+
while(x != 0) {
4+
long long y = x % 10;
5+
x = x / 10;
6+
reverseNum = 10 * reverseNum + y;
7+
}
8+
return (reverseNum < INT_MIN || reverseNum > INT_MAX) ? 0 : reverseNum;
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution(object):
2+
def isPalindrome(self, x):
3+
if x < 0:
4+
return False
5+
elif x == 0:
6+
return True
7+
else :
8+
prenum = x
9+
reverse = 0
10+
while x != 0:
11+
y = x % 10
12+
x = int(x / 10)
13+
reverse = y + 10 * reverse
14+
return reverse == prenum
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Determine whether an integer is a palindrome. Do this without extra space.
2+
3+
click to show spoilers.
4+
5+
Some hints:
6+
7+
Could negative integers be palindromes? (ie, -1)
8+
9+
If you are thinking of converting the integer to string, note the restriction of using extra space.
10+
11+
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?
12+
13+
There is a more generic way of solving this problem.
14+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Given a roman numeral, convert it to an integer.
2+
3+
Input is guaranteed to be within the range from 1 to 3999.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def romanToInt(self, s):
3+
hashmap = {
4+
'I': 1,
5+
'V': 5,
6+
'X': 10,
7+
'L': 50,
8+
'C': 100,
9+
'D': 500,
10+
'M': 1000
11+
};
12+
result = 0;
13+
for i in range(0,len(s)):
14+
if i == 0:
15+
result += hashmap[s[i]]
16+
elif hashmap[s[i - 1]] >= hashmap[s[i]]:
17+
result += hashmap[s[i]]
18+
elif hashmap[s[i - 1]] < hashmap[s[i]]:
19+
print(i)
20+
result += hashmap[s[i]] - 2 * hashmap[s[i - 1]]
21+
return result

0 commit comments

Comments
 (0)