A modified discrete least-squares method for optimal solutions in inverse problems