Skip to content

Commit a31b564

Browse files
✨ Day 28; Week 4 ✔️
1 parent 8dac0b4 commit a31b564

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@
3535
7. [Asteroid Collision](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/561/week-3-october-15th-october-21st/3502/) ➡️ [CPP Solution](Week3/asteroidCollision.cpp)
3636

3737

38-
## Week 4 🚧
38+
## Week 4
3939

4040
1. [Minimum Depth of Binary Tree](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3504/) ➡️ [CPP Solution](Week4/minDepth.cpp)
4141
2. [132 Pattern](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3505/) ➡️ [CPP Solution](Week4/find132pattern.cpp)
4242
3. [Bag of Tokens](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3506/) ➡️ [CPP Solution](Week4/bagOfTokensScore.cpp)
4343
4. [Stone Game IV](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3507/) ➡️ [CPP Solution](Week4/winnerSquareGame.cpp)
4444
5. [Champagne Tower](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3508/) ➡️ [CPP Solution](Week4/champagneTower.cpp)
4545
6. [Linked List Cycle II](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3509/) ➡️ [CPP Solution](Week4/detectCycle.cpp)
46+
7. [Summary Ranges](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/562/week-4-october-22nd-october-28th/3510/) ➡️ [CPP Solution](Week4/summaryRanges.cpp)
4647

4748
## Week 5 🚧
4849

Week4/summaryRanges.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution {
2+
public:
3+
vector<string> summaryRanges(vector<int>& nums) {
4+
int n = nums.size();
5+
vector<string> result;
6+
7+
if(n == 0) return result;
8+
9+
int start = nums[0], end = nums[0];
10+
string val;
11+
12+
for(int i = 1; i < n; ++i) {
13+
if(end + 1 == nums[i]) {
14+
end = nums[i];
15+
continue;
16+
}
17+
18+
if(start == end) {
19+
val = to_string(start);
20+
result.push_back(val);
21+
} else {
22+
val = to_string(start) + "->" + to_string(end);
23+
result.push_back(val);
24+
}
25+
26+
start = nums[i];
27+
end = nums[i];
28+
}
29+
30+
if(start == end) {
31+
val = to_string(start);
32+
result.push_back(val);
33+
} else {
34+
val = to_string(start) + "->" + to_string(end);
35+
result.push_back(val);
36+
}
37+
38+
return result;
39+
}
40+
};

0 commit comments

Comments
 (0)