Truth is, it doesn't really matter... but in general, you should write it so it is easily understood. Some helpful tips for making it easy to understand are:
If you are going up, it's easier to read a sharp (C up to D# instead of C up to Eb)
If you are going down, it's easier to read a flat (C down to Bb instead of C down to A#)
Use accidentals of the same key (key of G uses sharps, key of F uses flats)
Avoid mixing sharps and flats together (A# with Gb is awkward to read)
No unison enharmonics (don't write a B# and a C♮ in the same measure)
No reversed enharmonics (don't write a B# and a Cb in the same measure)
No inversed enharmonics (don't write a Cb and a C♮ in the same measure)
No contradicting accidentals (don't write Db and D# in the same measure)
Use the least amount of accidentals (reading A#, B, A# is easier than reading Bb, Cb, Bb)
Put every note on a letter if you can (Instead of writing C, B, Bb, G, Gb, F, Eb, C; it's better to write it as C, B, A#, G, F#, E#, D#, C because each note is assigned to a letter)
Follow music theory if it applies (sharps for augmented steps, flats for diminished steps)