You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in forward order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.
Kraken is m*n grids on a rectangular board. From the top left to reach the bottom right corner while moving one grid at a time in either the down, right or down-right diagonal directions
A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.
算法 链表 【LC总结】翻转链表 Swap in Pairs, Reverse in k-Group, Reverse LinkedList###Reverse a doubly linkedlist reverse singly linked list Iteration: {代码...} Recursion: {代码...} 二叉树 Subtree {代码...} Binary Tree Level Order Traversal If is required bottom-up, use Collections.reverse(res); ...
Problem Count the number of prime numbers less than a non-negative number, n. Note 用数组flag标记非质数,每当出现一个flag[i]为false,计数器count加一。关于质数有三点: 大于3的质数一定是奇数,如3,5,7; 奇数中的非质数也一定是奇数的乘积。 对于一个很大的数n,它的两个因数i和j中一定有一个小于n的开方,...
Merge Intervals Problem Given a collection of intervals, merge all overlapping intervals. Example Given intervals => merged intervals: {代码...} Challenge O(n log n) time and O(1) extra space. Note 忘了这题怎么做,汗颜无地。 边界: size < 2 sort by Comparator<Interval> loop: merge &...
Given a 2D grid, each cell is either an house 1 or empty 0 (the number zero, one), find the place to build a post office, the distance that post office to all the house sum is smallest. Return the smallest distance. Return -1 if it is not possible.
If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number of replacements needed for n to become 1?
Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 and v2. It's guaranteed there is no duplicate values in the linked list. If v1 or v2 does not exist in the given linked list, do nothing.
Given an array of n integer with duplicate number, and a moving window(size k), move the window at each iteration from the start of the array, find the maximum number inside the window at each moving.