This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. | |
* EXAMPLE | |
* Input: the node c from the linked list a->b->c->d->e | |
* Result: nothing is returned, but the new linked list looks like a->b->d->e | |
*/ | |
class deleteMiddle{ | |
public void deleteMiddle(Node node){ | |
if(node==NULL || node.next == NULL) | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
2.4 Write code to partition a linked list around a value x, | |
such that all nodes less than x come before all nodes greater than or equal to x. | |
*/ | |
class partition{ | |
public linkNode partition(linkNode node, int x){ | |
linkNode beforeStart = NULL; | |
linkNode beforeEnd = NULL; | |
linkNode afterStart = NULL; | |
linkNode afterEnd = NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the Ts digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list. | |
EXAMPLE | |
Input:(7-> 1 -> 6) + (5 -> 9 -> 2).Thatis,617 + 295. | |
Output: 2 -> 1 -> 9.That is, 912. | |
FOLLOW UP | |
Suppose the digits are stored in forward order. Repeat the above problem. EXAMPLE | |
Input:(6 -> 1 -> 7) + (2 -> 9 -> 5).Thatis,617 + 295. | |
Output: 9 -> 1 -> 2.That is, 912. | |
*/ | |
LinkedListNode addLists(LinkedListNode l1, LinkedListNode l2, int carry){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package us.xinbo.www; | |
/** | |
* Question: give you an integer, you have to duplicate a digit of this integer, return the biggest new number | |
* For example: input: 123, output: 1233 | |
* input: 132, output: 1332 | |
* input: -132, output: -1132 | |
* input: -321, output: -3211 | |
*/ | |
class Solution { | |
public static int findMax(int num){ |
OlderNewer