Leetcode 151: Reverse Words in a String

151. Reverse Words in a String  Total Accepted: 121339 Total Submissions: 769606 Difficulty: Medium Given an input string, reverse the string word by word. For example,Given s = “the sky is blue“,return “blue is sky the“. Update (2015-02-12):For C programmers: Try to solve it in-place in O(1) space. click to show clarification. Clarification: What constitutes …

Leetcode 92: Reverse Linked List II

https://leetcode.com/problems/reverse-linked-list-ii/   92. Reverse Linked List II  Total Accepted: 85657 Total Submissions: 293208 Difficulty: Medium Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note:Given m, n satisfy the following condition:1 ≤ m ≤ n ≤ length …

Leetcode 206: Reversed Linked List

https://leetcode.com/problems/reverse-linked-list/ 206. Reverse Linked List   Total Accepted: 149090 Total Submissions: 353930 Difficulty: Easy Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?   Code (Iterative) # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # …

Leetcode 130: Surrounding regions

https://leetcode.com/problems/surrounded-regions/ 130. Surrounded Regions   Total Accepted: 64022 Total Submissions: 378153 Difficulty: Medium Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. For example, X X X X X O O X X …

Leetcode 216: Combination Sum III

216. Combination Sum III https://leetcode.com/problems/combination-sum-iii/ Total Accepted: 45842 Total Submissions: 115036 Difficulty: Medium Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.   Example 1: Input: k = 3, …

Leetcode 202: Happy Number

https://leetcode.com/problems/happy-number/ Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops …

Leetcode 143: Reorder List

https://leetcode.com/problems/reorder-list/ Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes’ values. For example,Given {1,2,3,4}, reorder it to {1,4,2,3}.   Code # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def reorderList(self, head): …