haoel / leetcode

LeetCode Problems' Solutions
17.58k stars 4.91k forks source link

TenthLine - bash #278

Open hinell opened 2 years ago

hinell commented 2 years ago

Well I think the example given in the TenthLine.sh is a pure cheating. Here a few good examples for faster bash solution:

declare i=1;
while read line;
do ((++i)); [[ i -eq 11 ]] && echo $line;
done < file.txt

or

IFS=$'\n' readarray arr < file.txt; echo ${arr[9]}