Don't LeetCode Yet - 0 - Usage of LIOJ
Course link
Things to know before LeetCode!
LIOJ Interface
Lidemy OJ: An online judge system based on the open-source OJ project from Qing-Dao University
File I/O using nodejs library
readline
var readline = require('readline');
var lines = []
var rl = readline.createInterface({
input: process.stdin
});
// push one line to the array lines
rl.on('line', function (line) {
lines.push(line)
});
// After all the input, call the solve() function
rl.on('close', function() {
solve(lines)
})
//-------------------------above using readline to get input---------
//-------------------------put solution below------------------------
function solve(lines){
// solution here
}Test the solution on local machine
Need NodeJS installed to run the code above.
Recommended practice: write an input file separately (input.txt) andcat
out the content then pass (pipe) it to the program (code.js):cat input.txt | node code.js
Test the solution online
I found jsbin quite useful for testing. It’s really easy to use and we can see the result right away.
Project 0
Problem 1001
Just copy past the code!
Use .split()
to SPLIT a line into an array.
Problem 1002
SPOILER ALERT! Not Very Smart Solution below!
function solve(lines) { |
It could be better to use variable to store Number(tmp[0])
and Number(tmp[1])
. So the code will looks cleaner.
Use ===
to compare with number 0
.
Practice with problem 1003, 1004 and 1010
Just to get familiar with the OJ system.
In problem 1004 Use BigInt()
to process BIG numbers.