Current streak:
0 days
Longest streak:
11 days
Less
More
Node* findMiddle(Node* head) {
if (!head || !head->next) {
return head;
}
int len = 0;
Node* current = head;
while (current) {
current = current->next;
len++;
}
current = head;
for (int i = 1; i <= len / 2; i++) {
current = current->next;
}
return current;
}
from os import *
from sys import *
from collections import *
from math import *
def stringSum(num1: str, num2: str) -> str:
result = ""
i = len(num1) - 1
j = len(num2) - 1
carry = 0
while i >= 0 or j >= 0 or carry:
_sum = 0
if i >= 0:
_sum += int(num1[i])
i -= 1
if j >= 0:
_sum += int(num2[j])
j -= 1
_sum += carry
carry = _sum // 10
result += str(_sum % 10)
return result[::-1] # Reverse the string to get the correct order
#include <bits/stdc++.h>
string leftRotate(string str, int d) {
int n = str.size(); // Get the length of the string
if (n == 0 || d == 0 || d % n == 0) {
return str; // No rotation needed
}
d = d % n;
return str.substr(d) + str.substr(0, d);
}
string rightRotate(string str, int d) {
int l = str.size();
if (l == 0 || d == 0 || d % l == 0) {
return str; // No rotation needed
}
d = d % l;
return str.substr(l - d) + str.substr(0, l - d);
}