A compound of formula or a pharmaceutically acceptable salt thereof wherein L 1 is -O-; L 2 is selected from the group consisting of -O-, -CH 2 -, -S-, -NH-, -NHC(=O)-, -C(=O)-, -C(=O)NH-, -S(=O)-, -S(=O) 2 -, -NHS(=O) 2 - and -S(=O) 2 NH-, wherein the above groups are optionally substituted by one or more R 4; R 1 is selected from the group consisting of hydrogen, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl, wherein the above C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl are optionally substituted by one or more R 4; R 2 is selected from the group consisting of hydrogen, halogen, cyano, hydroxyl, thiol, amino, COOH, -CONH 2, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl, wherein the above hydroxyl, thiol, amino, COOH, -CONH 2, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl are optionally substituted by one or more R 4; B is selected from the group consisting of aryl and heteroaryl; L 3 is selected from the group consisting of C 0-6 alkylene, imino, -O-, -S-, -S(=O)- and -S(=O) 2 -, wherein the above C 0-6 alkylene and imino are optionally substituted by one or more R 4; R 3 is selected from the group consisting of hydrogen, amino, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl, wherein the above amino, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl are optionally substituted by one or more R 4; or R 3 and L 3 together with the adjacent atom at the ring B form a saturated or unsaturated 5-8 membered ring, the 5-8 membered ring is optionally substituted by one or more R 4; n is 0, 1, 2, 3, 4 or 5; R 4 is selected from the group consisting of halogen, cyano, -R, -OR, =O, -SR, -NR 2, =NR, -C(halogen) 3, -CR(halogen) 2,-CR 2 (halogen), -OCN, -SCN, -N=C=O, -NCS, -NO, -NO 2, -NRC(=O)R, -NRC(=O)OR, -NRC(=O)NRR, -C(=O)NRR, -C(=O)OR, -OC(=O)NRR, -OC(=O)OR, -C(=O)R, -S(=O) 2 OR, -S(=O) 2 R, -OS(=O) 2 OR, -S(=O) 2 NRR, -S(=O)R, -NRS(=O) 2 R, -NRS(=O) 2 NRR, -NRS(=O) 2 OR, -OP(=O) 2, -P(=O) 2, -C(=O)R, -C(=S)R, -C(=O)OR, -C(=S)OR, -C(=O)SR, -C(=S)SR, -C(=O)NRR, -C(=S)NRR, -C(=NR)NRR and -NRC(=NR)NRR; R is independently selected from the group consisting of H, C 1-8 alkyl, C 3-8 cyclohydrocarbyl, 3-8 membered heterocyclohydrocarbyl, aryl, heteroaryl, arylalkyl and heteroarylalkyl. L 1 is -O-; L 2 is selected from the group consisting of -O-, -CH 2 -, -S-, -NH-, -NHC(=O)-, -C(=O)-, -C(=O)NH-, -S(=O)-, -S(=O) 2 -, -NHS(=O) 2 - and -S(=O) 2 NH-, wherein the above groups are optionally substituted by one or more R 4; R 1 is selected from the group consisting of hydrogen, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl, wherein the above C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl are optionally substituted by one or more R 4; R 2 is selected from the group consisting of hydrogen, halogen, cyano, hydroxyl, thiol, amino, COOH, -CONH 2, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl, wherein the above hydroxyl, thiol, amino, COOH, -CONH 2, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl are optionally substituted by one or more R 4; B is selected from the group consisting of aryl and heteroaryl; L 3 is selected from the group consisting of C 0-6 alkylene, imino, -O-, -S-, -S(=O)- and -S(=O) 2 -, wherein the above C 0-6 alkylene and imino are optionally substituted by one or more R 4; R 3 is selected from the group consisting of hydrogen, amino, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl, wherein the above amino, C 1-10 alkyl, C 2-10 alkenyl, C 2-10 alkynyl, C 3-10 cyclohydrocarbyl, 3-10 membered heterocyclohydrocarbyl, aryl and heteroaryl are optionally substituted by one or more R 4; or R 3 and L 3 together with the adjacent atom at the ring B form a saturated or unsaturated 5-8 membered ring, the 5-8 membered ring is optionally substituted by one or more R 4; n is 0, 1, 2, 3, 4 or 5; R 4 is selected from the group consisting of halogen, cyano, -R, -OR, =O, -SR, -NR 2, =NR, -C(halogen) 3, -CR(halogen) 2,-CR 2 (halogen), -OCN, -SCN, -N=C=O, -NCS, -NO, -NO 2, -NRC(=O)R, -NRC(=O)OR, -NRC(=O)NRR, -C(=O)NRR, -C(=O)OR, -OC(=O)NRR, -OC(=O)OR, -C(=O)R, -S(=O) 2 OR, -S(=O) 2 R, -OS(=O) 2 OR, -S(=O) 2 NRR, -S(=O)R, -NRS(=O) 2 R, -NRS(=O) 2 NRR, -NRS(=O) 2 OR, -OP(=O) 2, -P(=O) 2, -C(=O)R, -C(=S)R, -C(=O)OR, -C(=S)OR, -C(=O)SR, -C(=S)SR, -C(=O)NRR, -C(=S)NRR, -C(=NR)NRR and -NRC(=NR)NRR; R is independently selected from the group consisting of H, C 1-8 alkyl, C 3-8 cyclohydrocarbyl, 3-8 membered heterocyclohydrocarbyl, aryl, heteroaryl, arylalkyl and heteroarylalkyl.