File tree 5 files changed +49
-19
lines changed
5 files changed +49
-19
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Algorithms
2
2
3
- ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-143/1571 -1f425f.svg )
4
- ![ problems-solved-java] ( https://img.shields.io/badge/Java-143/1571 -1abc9c.svg )
5
- ![ problems-solved-python] ( https://img.shields.io/badge/Python-143/1571 -1abc9c.svg )
3
+ ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-161/2081 -1f425f.svg )
4
+ ![ problems-solved-java] ( https://img.shields.io/badge/Java-161/2081 -1abc9c.svg )
5
+ ![ problems-solved-python] ( https://img.shields.io/badge/Python-161/2081 -1abc9c.svg )
6
6
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
7
7
[ ![ cp] ( https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg )] ( https://github.com/anishLearnsToCode/competitive-programming )
8
8
68
68
| 219 | [ Contains Duplicate II] ( https://leetcode.com/problems/contains-duplicate-ii ) | [ ![ Java] ( assets/java.png )] ( src/ContainsDuplicateII.java ) [ ![ Python] ( assets/python.png )] ( python/contains_duplicate_ii.py ) |
69
69
| 225 | [ Implement Stack using Queues] ( https://leetcode.com/problems/implement-stack-using-queues ) | [ ![ Java] ( assets/java.png )] ( src/MyStack.java ) [ ![ Python] ( assets/python.png )] ( python/implement_stack_using_queues.py ) |
70
70
| 226 | [ Invert Binary Tree] ( https://leetcode.com/problems/invert-binary-tree ) | [ ![ Java] ( assets/java.png )] ( src/InvertBinaryTree.java ) [ ![ Python] ( assets/python.png )] ( python/invert_binary_tree.py ) |
71
+ | 226 | [ Summary Ranges] ( https://leetcode.com/problems/summary-ranges/ ) | [ ![ Java] ( assets/java.png )] ( src/SummaryRanges.java ) [ ![ Python] ( assets/python.png )] ( python/summary_ranges.py ) |
71
72
| 231 | [ Power of Two] ( https://leetcode.com/problems/power-of-two ) | [ ![ Java] ( assets/java.png )] ( src/PowerOf2.java ) [ ![ Python] ( assets/python.png )] ( python/is_power_of_2.py ) |
72
73
| 232 | [ Implement Queue Using Stacks] ( https://leetcode.com/problems/implement-queue-using-stacks ) | [ ![ Java] ( assets/java.png )] ( src/MyQueue.java ) [ ![ Python] ( assets/python.png )] ( python/implement_queue_using_stacks.py ) |
73
74
| 234 | [ Palindrome Linked Lists] ( https://leetcode.com/problems/palindrome-linked-list ) | [ ![ Java] ( assets/java.png )] ( src/PalindromeLinkedList.java ) [ ![ Python] ( assets/python.png )] ( python/palindrome_linked_list.py ) |
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+
4
+ class Solution :
5
+ def getRangeString (self , start : int , end : int ) -> str :
6
+ return f'{ start } ' if start == end else f'{ start } ->{ end } '
7
+
8
+ def summaryRanges (self , array : List [int ]) -> List [str ]:
9
+ if len (array ) == 0 : return []
10
+ result = []
11
+ startIndex , index = 0 , 1
12
+ while index < len (array ):
13
+ if array [index ] > array [startIndex ] + (index - startIndex ):
14
+ result .append (self .getRangeString (array [startIndex ], array [index - 1 ]))
15
+ startIndex = index
16
+ index += 1
17
+ result .append (self .getRangeString (array [startIndex ], array [len (array ) - 1 ]))
18
+ return result
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ public boolean judgeCircle(String moves) {
3
3
int vertical = 0 , horizontal = 0 ;
4
4
for (int index = 0 ; index < moves .length () ; index ++) {
5
5
switch (moves .charAt (index )) {
6
- case 'U' -> vertical ++;
7
- case 'R' -> horizontal ++;
8
- case 'D' -> vertical --;
9
- case 'L' -> horizontal --;
6
+ case 'U' : vertical ++; break ;
7
+ case 'R' : horizontal ++; break ;
8
+ case 'D' : vertical --; break ;
9
+ case 'L' : horizontal --; break ;
10
10
}
11
11
}
12
12
return vertical == 0 && horizontal == 0 ;
Original file line number Diff line number Diff line change
1
+ import java .util .ArrayList ;
2
+ import java .util .List ;
3
+
4
+ public class SummaryRanges {
5
+
6
+ private String getRangeString (int start , int end ) {
7
+ return end == start ? start + "" : start + "->" + end ;
8
+ }
9
+
10
+ public List <String > summaryRanges (int [] array ) {
11
+ if (array .length == 0 ) return new ArrayList <>();
12
+ List <String > result = new ArrayList <>();
13
+ int startIndex = 0 ;
14
+ for (int index = 1 ; index < array .length ; index ++) {
15
+ if (array [index ] > array [startIndex ] + (index - startIndex )) {
16
+ result .add (getRangeString (array [startIndex ], array [index - 1 ]));
17
+ startIndex = index ;
18
+ }
19
+ }
20
+ result .add (getRangeString (array [startIndex ], array [array .length - 1 ]));
21
+ return result ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change 1
1
import java .util .HashSet ;
2
2
import java .util .Set ;
3
3
4
- class TreeNode {
5
- int val ;
6
- TreeNode left ;
7
- TreeNode right ;
8
- TreeNode () {}
9
- TreeNode (int val ) { this .val = val ; }
10
- TreeNode (int val , TreeNode left , TreeNode right ) {
11
- this .val = val ;
12
- this .left = left ;
13
- this .right = right ;
14
- }
15
- }
16
4
17
5
public class TwoSumIVInputIsABST {
18
6
Set <Integer > elements = new HashSet <>();
You can’t perform that action at this time.
0 commit comments