It depends on the definition of the term 'brain'.
In the field of comparative anatomy, the brain is understood as the largest accumulation of nervous tissue that forms with a high degree of centralization of the nervous system. Typically, each organism has only one such brain.
However, some invertebrates have comparable-sized nerve nodes (ganglia) in addition to the main brain, which possess a certain degree of autonomy. For example, it is sometimes claimed that an octopus has nine brains. In reality, it has one brain and eight large ganglia in its tentacles, each of which can occupy up to a quarter of the volume of the main brain. These ganglia allow the tentacles to perform certain actions independently of each other.
In arthropods, such as spiders and many insects, the subesophageal ganglion plays an important role and is also comparable in size to the brain. In large dinosaurs, such as the diplodocus, the spinal canal in the sacral vertebrae was enlarged, containing significantly more nervous tissue than the skull. However, this is not a second brain but rather a part of the spinal cord responsible for controlling the hind limbs and tail.
Indeed, organisms with two brains occur only as rare anomalies in the process of embryonic development. For example, two-headed snakes and turtles can be viable but face difficulties in decision-making and coordination of movements.