An algorithm for solving a variant of the traveling salesman problem was designed and implemented using quantum approximation optimization method,and simulated on a simulator.The results showed that,with sufficient quantum bits,the algorithm can solve the variant of the traveling salesman problem with polynomial time on a quantum computer,and achieve an approximation ratio within 1.5.This provides a way to solve NP-hard problems using quantum computers.