My AC code just use bash array


  • 0
    L
    empty=" "
    i=0
    while read line
    do 
    	if [ $i -eq 0 ]; then
    		array=($line)
    	else
    		tmp=($line)
    		len=${#tmp[@]}
    		k=0
    		while [ $k -lt $len ]
    		do 
    			array[$k]=${array[$k]}$empty${tmp[$k]}
    			let k++
    		done
    	fi
    	let i++
    done < file.txt
    
    #print result
    for ((i=0;i<${#array[@]};i++));
    do
    	echo ${array[$i]}
    done

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.