New York Knicks forward Carmelo Anthony (7) dunks over Miami...

New York Knicks forward Carmelo Anthony (7) dunks over Miami Heat forward Derrick Williams (22) during the first half of an NBA basketball game, Tuesday, Dec. 6, 2016, in Miami. Credit: AP / Lynne Sladky

MIAMI — Carmelo Anthony used to have to battle LeBron James, Dwyane Wade and Chris Bosh whenever he made the trip to South Beach. But the Heat is an injury-riddled team in transition that has some players you wouldn’t know without a roster sheet or boxscore in front of you.

Anthony wouldn’t let the Knicks lose to this group.

The offense was sputtering and Anthony couldn’t find his shot until the closing minutes of the first half. It carried through into the second half as Anthony finished with a season-high matching 35 points and gave the Knicks the lift they needed to put away Miami, 114-103, for their fourth straight win.

“I needed to get myself going,” Anthony said. “I knew that. I wanted to get myself going some way, somehow.”

The only negative for the Knicks (12-9) was Derrick Rose left the game in the third quarter with back spasms and never returned.

Rose said it “calmed down” after the game, but isn’t sure whether he will be able to play Wednesday when LeBron James and the NBA champions Cavaliers visit Madison Square Garden.

“I’m not concerned,” Rose said. “There’s nothing structure wise that’s bothering me. It’s just a muscular problem. We’ll be able to see tomorrow.

“I’m going to be cautious for sure. But if I can go, I’m going to go. It’s a big game for us, and I love playing against them. I just have to be smart about it.”

The Knicks are surging lately, having won nine of their last 12 games. It’s the first time they’re three games above .500 since their 54-win team in 2012-13.

“We’re building,” Anthony said. “Anytime you can put together some wins, you feel confident, you feel comfortable, you feel like you’re heading in the right direction. I really feel like we’re doing that, heading in the right direction.”

But the Knicks face a steep challenge against the Cavaliers and with James expected to be out to ruin Phil Jackson’s night. James is still upset that Jackson referred to his friends and business partners as a “posse.”

That’s what made this game so important for the Knicks. They didn’t want to waste a golden opportunity against a beaten-down team.

Miami was without four of its top eight players: Justise Winslow, Dion Waiters, Josh Richardson and James Johnson. But Hornacek kept cautioning that teams which are banged up are dangerous because the seldom-used players thrust into big minutes want to prove themselves.

The Heat was determined to surprise the Knicks. Miami led by nine late in the first half, but then Anthony got going.

After starting 2-for-9 with nine points through the first 23 minutes of the game, he shot 11-for-18 and scored 26 the rest of the way. The Knicks outscored Miami 61-49 in the second half.

The Knicks got double-doubles from Kristaps Porzingis (14 points, 12 rebounds) and Joakim Noah (10 and 10). Kyle O’Quinn scored 12 points.

Miami (7-14) was led by Goran Dragic’s 29 points. Hassan Whiteside added 23 and 14 rebounds.

There were nine lead changes and ties in the third quarter before the Knicks created some separation. Anthony sparked a 14-4 run that put the Knicks ahead 82-72 with 49.8 seconds left in the third. Anthony scored nine points in the surge, two on three-pointers and he also converted a three-point play inside.

The Knicks opened the fourth scoring six straight points and 11 of the first five and pushed their lead to 95-81 after Lance Thomas’ jumper with 7:50 to go.

Miami never got it under eight the rest of the way.

“We just came out in the second half knowing we had to win the game,” Porzingis said. “Melo got going and hit some tough shots. We came out with a different energy.”

Newsday LogoCritical LI Information You NeedDigital Access$1 for 5 months