We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
in case if you don't want to use sort | uniq etc. for some reason:
#!/bin/shreaddummyread-aARRAYFILTER=()# X (listof X) -> Booleanmember(){foriin${@:2};doif[[$1-eq$i]];thenreturn0fidonereturn1}# X (listof X) -> (listof X)filter(){new=()foriin${@:2};doif![[$i-eq$1]];thennew+=($i)fidone# bash functions don't return values, so we use global vars insteadFILTER=${new[@]}}# (listof X) -> Xlonelyint(){# () to properly create an array from elementarray=("$@")count=0forcurrentin${array[@]};dolet'count++'rest=${array[@]:$count}ifmember$current$rest;then# this filter doesn't really work# array=(2 32 2) current=2 => array=(3)#new=${array[@]/$current/}filter$current${array[@]}lonelyint${FILTER[@]}elseecho"$current"exit0fidone}lonelyint${ARRAY[@]}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer - Bash!
You are viewing a single comment's thread. Return to all comments →
in case if you don't want to use sort | uniq etc. for some reason: