added leetcode problem 24 and 29 #518
Open
+125
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for Swap Nodes in Pairs
Description
This PR adds the solution for the problem “Swap Nodes in Pairs”.
The approach uses an iterative method with a dummy node, swapping adjacent nodes by changing pointers rather than values. The solution efficiently handles empty lists, single-node lists, and general cases.
Dependencies: None, uses standard Python ListNode definition.
Time Complexity: O(n), where n is the number of nodes in the linked list (each node is visited once).
Space Complexity: O(1), only a few pointers are used, no extra data structures.
Put check marks:
Added problem & solution under correct topic.
Specified Space & Time complexity.
Specified difficulty level, tag & Note(if any).
How Has This Been Tested?
Tested with multiple examples:
[1,2,3,4] → [2,1,4,3]
[] → []
[1] → [1]
[1,2,3] → [2,1,3]
Guidelines Checklist
My code follows the style guidelines of this project
I have performed a self-review of my own code
I have commented my code so that it is easy to understand
I have made corresponding changes to the documentation
My changes generate no new warnings
Any dependent changes have been merged and published in downstream modules
Pull Request for Divide Two Integers
Description
This PR adds the solution for the problem “Divide Two Integers”.
The approach uses bit manipulation and repeated subtraction to calculate the quotient without using *, /, or % operators.
It handles edge cases such as overflow and negative results efficiently.
Dependencies: None, uses standard Python integer operations.
Time Complexity: O(log(dividend)^2), because the divisor is doubled each time in repeated subtraction.
Space Complexity: O(1), only constant extra variables are used.
Put check marks:
Added problem & solution under correct topic.
Specified Space & Time complexity.
Specified difficulty level, tag & Note(if any).
How Has This Been Tested?
Tested with multiple examples:
dividend = 10, divisor = 3 → 3
dividend = 7, divisor = -3 → -2
Edge case: dividend = -231, divisor = -1 → 231-1
Guidelines Checklist
My code follows the style guidelines of this project
I have performed a self-review of my own code
I have commented my code so that it is easy to understand
I have made corresponding changes to the documentation
My changes generate no new warnings
Any dependent changes have been merged and published in downstream modules