State lawmakers finalized a deal on Thursday to legalize recreational marijuana in New York, paving the way for a potential $4.2 billion industry that could create tens of thousands of jobs and become one of the largest markets in the country.