Alphabet and Apple shares gain after judge’s ruling is better for the companies than investors had feared