₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,808 members, 8,442,347 topics. Date: Friday, 10 July 2026 at 02:48 AM

Toggle theme

Gistray's Posts

Nairaland ForumGistray's ProfileGistray's Posts

1 2 3 4 5 6 7 8 ... 31 32 33 34 35 36 37 38 39 (of 56 pages)

SportsRe: AFCON 2021: Burkina Faso Vs Ethiopia (1 - 1) On 17th January 2022 by gistray: 12:45pm On Jan 17, 2022
Shitt teams
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 8:03pm On Jan 15, 2022
tensazangetsu20:
Its the same thing I did too in Javascript the only difference is the LinkedList data structure will be a constructor( I dont think you have to created this, its always given in the code) and you add a math.floor to the new carry value in the while loop every other variable can be declared with const the ones reassigned can be done with let but its the exact same code.
Ok sir
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 7:59pm On Jan 15, 2022
tensazangetsu20:
A linked list is its own data structure. You are taking it as an array but it isn't. That's why you are struggling.
Can you help me in JavaScript?
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 7:59pm On Jan 15, 2022
Deicide:
What you did there is not linked list
What matters is the returned value right v
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 7:56pm On Jan 15, 2022
tensazangetsu20:
So practically you are going to construct the new LinkedList and as you are iterating both linked list you are going to add both values and put them in the new linked list then return back that list.
No, convert the return array to a list in JavaScript.

What's important is the end product right?

I can't even tell what a list is in JavaScript... Is it an object or what?
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 7:47pm On Jan 15, 2022
tensazangetsu20:
True but you aren't event iterating the linked list the right way. You are taking it as an array
Maybe I just convert the array to a list afterwards?
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 7:46pm On Jan 15, 2022
tensazangetsu20:
public static class LinkedList {
public int value;
public LinkedList next;

public LinkedList(int value) {
this.value = value;
this.next = null;
}
}

public LinkedList sumOfLinkedLists(LinkedList linkedListOne, LinkedList linkedListTwo) {
LinkedList nextHeadPointer = new LinkedList(0);
LinkedList currentNode = nextHeadPointer;
int carry = 0;

LinkedList nodeOne = linkedListOne;
LinkedList nodeTwo = linkedListTwo;
while (nodeOne != null || nodeTwo != null || carry != 0){
int valueOne = (nodeOne != null) ? nodeOne.value : 0;
int valueTwo = (nodeTwo != null) ? nodeTwo.value : 0;
int sumOfValues = valueOne + valueTwo + carry;

int newValue = sumOfValues % 10;
LinkedList newNode = new LinkedList(newValue);
currentNode.next = newNode;
currentNode = newNode;

carry = sumOfValues / 10;
nodeOne = (nodeOne != null) ? nodeOne.next : null;
nodeTwo = (nodeTwo != null) ? nodeTwo.next : null;

}
return nextHeadPointer.next;
}

This is the solution in Java.
Mind adding some comments
SportsRe: Nigeria Vs Sudan : AFCON 2021 : 3 - 1 On 15th January 2022 by gistray: 6:53pm On Jan 15, 2022
I can play football better than Sadiq


I believe his father is a rich Aboki that forced his son to play football
SportsRe: Nigeria Vs Sudan : AFCON 2021 : 3 - 1 On 15th January 2022 by gistray: 6:47pm On Jan 15, 2022
ABOKI NA ABOKI
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 6:01pm On Jan 15, 2022
LikeAking:
My solution.

function addTwoNumbers(a,b){

let xy = a.toString().replace(/,|\s/g,""wink

let xz = b.toString().replace(/,|\s/g,""wink

let zzz = Number(xy) + Number(xz)

return zzz.toString().split(""wink.reverse().join(""wink

}
console.log(addTwoNumbers([9,9,9,9,9,9,9], [9,9,9,9]))

output = 89990001

NL dey convert some brackets to this green guy wink.

Any wia u see am use ) = bracket
Hard to read.


How about not using regex
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 4:29pm On Jan 15, 2022
tensazangetsu20:
True but you aren't event iterating the linked list the right way. You are taking it as an array
is there a list in javascript?
shocked shocked shocked that's whats confusing me
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 4:19pm On Jan 15, 2022
LikeAking:
U have learnt JS.

Nice one.

Use map.

use reduce.

reverse the arr with reverse.




Also drop the link.

I was trying to avoid normal javascript array methods at all cost
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 4:19pm On Jan 15, 2022
tensazangetsu20:
You aren't even meant to solve this question like this at all. This is the famous sum of two linked list question asked in companies like Facebook and Google. I will send my solution but in java later. Lemme book space.
I believe they are different ways to solve the question.
ProgrammingRe: Leetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 2:31pm On Jan 15, 2022
HELLO
ProgrammingLeetcode Solution Error Please Help Its Just Driving Me Crazy by gistray(op): 2:17pm On Jan 15, 2022
So i am solving this problem on leetcode and my solutions runs as expected on the console.
But if I run the code on Leetcode is throws an error

THE QUESTION

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 contains a single digit. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Example 2:

Input: l1 = [0], l2 = [0]
Output: [0]
Example 3:

Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]



MY SOLUTION

var addTwoNumbers = function(l1, l2) {

var alpha1 = ""
var alpha2 = ""
var arr = []


// Looping through first list l1

for(var i = 0; i< l1.length; i++){
alpha1 = l1[i]+alpha1

// converting l1 to string and setting it to ALPHA 1
}

// Looping through second list L2
for(var i = 0; i< l2.length; i++){
alpha2 = l2[i]+alpha2

// converting l2 to string and setting it to ALPHA 2
}
// Coverting alpha1 and apha2 to intergets and making their sum to a new variable string "New"
var New = parseInt(alpha1) + parseInt(alpha2)
New = New + ""

for(var i=0;i<New.length; i++){
// Pushing the New variable is reverse order to arr and also converting it back to interger
arr.push(parseInt(New[New.length-i-1]))

}
// Returning the array
return arr
};
addTwoNumbers([9,9,9,9,9,9,9],[9,9,9,9])



THE ERROR ON LEETCODE

Line 51 in solution.js
throw new TypeError(__serialize__(ret) + " is not valid value for the expected return type ListNode"wink;
^
TypeError: [null,null,null] is not valid value for the expected return type ListNode



WORST PART IS, THERE'S NO LINE 51 ON THE LEETCODE CODE MODULE LOL


I AM USING JAVASCRIPT
SportsRe: AFCON - Morocco Vs Comoros (2 - 0) On 14th January 2022 by gistray: 5:03pm On Jan 14, 2022
Let me watch it for watching sake
PhonesRe: Windscribe VPN Mocks Nigerians And Buhari After Twitter Ban Was Lifted (Photos) by gistray: 2:11pm On Jan 13, 2022
.
EducationRe: Composite Car Produced By University Of Jos Students (Pictures) by gistray: 9:13am On Jan 13, 2022
Unfortunately, it will die a natural death
RomanceRe: n by gistray: 8:59pm On Jan 12, 2022
.

PoliticsRe: My Friend Was Given A Photocopy Of His NIN Slip by gistray: 4:59pm On Jan 12, 2022
charlsecy:
Ok, but it's completely acceptable as a means of identification.
Not everywhere.


I know the stress I've past through with with flutterwave
TV/MoviesRe: 6 Nigerian Movies To Watch Out For In 2022 by gistray: 3:52pm On Jan 12, 2022
Idiot sir

PoliticsRe: My Friend Was Given A Photocopy Of His NIN Slip by gistray: 1:30pm On Jan 12, 2022
charlsecy:
Not sure they actively issue original currently. You can print the digital and it becomes original.
It can't be original trust me

I have the plastic version of printed copy


It will always state that it's

"Digital copy"
SportsRe: Nigeria Vs Egypt: AFCON 2021: (1 - 0) On 11th January 2022 by gistray: 6:44pm On Jan 11, 2022
Ejuke is a fooool
SportsRe: Nigeria Vs Egypt: AFCON 2021: (1 - 0) On 11th January 2022 by gistray: 6:38pm On Jan 11, 2022
This is a 2:0 match
SportsRe: Nigeria Vs Egypt: AFCON 2021: (1 - 0) On 11th January 2022 by gistray: 6:36pm On Jan 11, 2022
Iheanacho is kind of tired
SportsRe: Nigeria Vs Egypt: AFCON 2021: (1 - 0) On 11th January 2022 by gistray: 5:38pm On Jan 11, 2022
This Simon guy the try
RomanceRe: This Wh0r£ Has Just Taken ENTITLEMENT MENTALITY To The Next Level!! (Photos) by gistray: 9:55am On Jan 11, 2022
The chat is over 10 years old.

That's a Java phone
PoliticsRe: My Friend Was Given A Photocopy Of His NIN Slip by gistray: 11:15pm On Jan 10, 2022
charlsecy:
Not true. You can get the plastic [or laminated] as soon you have a NIN for a fee of N400 or N1,000 [plus service fee]. Read How to Print Your Improved NIN Slip
This is digital copy and not original
PhonesRe: How Much Is It To Changed Iphone X Battery by gistray: 6:16pm On Jan 10, 2022
40k original
CelebritiesRe: Dayo Kujore Is Dead by gistray: 5:48pm On Jan 10, 2022
He didn't win a Grammy though

1 2 3 4 5 6 7 8 ... 31 32 33 34 35 36 37 38 39 (of 56 pages)