File: root - text - article - 2019 - 10 - daily-problem-add-two-numbers-as-a-linked-list.txt
Tags: 每天算法, 算法, 数据结构, 链表, daily problem, linked list, programming, algorithm, | English | Home Page | Category: Computing | 434 Views, 28370 Search Bots | 214 Words
| Browse | Archive
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Tags: 每天算法, 算法, 数据结构, 链表, daily problem, linked list, programming, algorithm, | English | Home Page | Category: Computing | 434 Views, 28370 Search Bots | 214 Words
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
This problem was recently asked by Microsoft: You are given two 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.
Example:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.
Here is the function signature as a starting point (in Python):
Why Python? We recommend using Python as a generalist language for interviewing, as it is well-regarded in the tech industry and used across Google/YouTube, Facebook/Instagram, Netflix, Uber, Dropbox, Pinterest, Spotify, etc., It is easy to learn with readable syntax, and very similar in structure to other popular languages like Java, C/C++, Javascript, PHP, Ruby, etc. Python is generally faster to read/write though, which makes it ideal for interviews. You can, of course, use any language you like!
Tags: 每天算法, 算法, 数据结构, 链表, daily problem, linked list, programming, algorithm, | English | Home Page | Cateogry: Computing | 434 Views, 28370 Search Bots | 214 Words Example:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.
Here is the function signature as a starting point (in Python):
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def addTwoNumbers(self, l1, l2, c = 0):
# Fill this in.
l1 = ListNode(2)
l1.next = ListNode(4)
l1.next.next = ListNode(3)
l2 = ListNode(5)
l2.next = ListNode(6)
l2.next.next = ListNode(4)
result = Solution().addTwoNumbers(l1, l2)
while result:
print result.val,
result = result.next
# 7 0 8
Why Python? We recommend using Python as a generalist language for interviewing, as it is well-regarded in the tech industry and used across Google/YouTube, Facebook/Instagram, Netflix, Uber, Dropbox, Pinterest, Spotify, etc., It is easy to learn with readable syntax, and very similar in structure to other popular languages like Java, C/C++, Javascript, PHP, Ruby, etc. Python is generally faster to read/write though, which makes it ideal for interviews. You can, of course, use any language you like!
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Related Articles
- Progess made
- Autorun.inf Virus Protection
- Fix Brackets
- Daily Interview Problem: Minimum Removals for Valid Parenthesis
- Algorithm Interview Question: Max and Min with Limited Comparisons
- [Daily Problem] Angles of a Clock
- Daily Interview Puzzle: Falling Dominoes
- Palindrome Integers
- Delphi Dynamic Array
- Find Pythagorean Triplets
©2006~2024 SteakOverCooked - 0.0075 Seconds(s) - 2634.635 KB/s - 8 Online
Memory: 493.43 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
![](/images/top.jpg)
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !