Body flexibility plays a significant role in fish propulsion and has been increasingly incorporated into robotic fish design. However, the functional significance of spatially varying body stiffness observed in real fish remains insufficiently under stood. This letter presents a reinforcement learning framework for optimizing the distributed passive stiffness of a motor-driven robotic fish. A multi-link dynamics model was developed to approximate continuously varying body stiffness, and its hydro dynamic parameters were identified and validated through swimming experiments. Based on the optimized stiffness distributions, we fabricated two robotic fish tails targeting fast swimming and energy-saving swimming, respectively. Experiments at the target operating condition show that the fast-swimming design increased swimming speed by 36.1% compared with the baseline, while the energy-saving design reduced the experimental cost of transport by 53.5%. Numerical fluid-structure simulations further reveal that the fast-swimming design strengthens wake vortices for increased thrust, whereas the energy-saving design promotes passive posterior deformation and an asymmetric wake associated with the lower cost of transport. These results demonstrate that distributed stiffness tuning provides an effective mechanism for improving robotic fish performance and offer design guidelines for bio-inspired flexible swimmers.