刚刚我经历了可能是2017年3月22号的最大的大起大落。
2.
Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
想了半天才弄懂题目的意思,但是一眼就能看出怎么解啊,看了下居然是medium,抱着觉得整道题的难度就在读懂题目上的心态把代码写完了。
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public String reverse(String s) {
//借用别人的方法,自己实现过很多次了,懒得再写一次
int length = s.length();
if (length <= 1)
return s;
String left = s.substring(0, length / 2);
String right = s.substring(length / 2, length);
return reverse(right) + reverse(left);
}