If you were married to a U.S. citizen who died before you were able to get permanent residence in the U.S. (a "green card") through the marriage, you quite possible can get the green card anyway.
If your spouse died before filing any petition to start the green card process, you can file a petition on your own to let U.S. Citizenship and Immigration Services (USCIS) know that you were married to a U.S. citizen and that therefore you are eligible for a green card. (See I.N.A. Section 201(b)(2)(A)(i).)
There are several requirements, however.
First, you and your deceased spouse must not have been divorced or legally separated at the time of your spouse's death. It's okay if you were living apart; the only thing that matters is that you weren't legally separated, that is, by court order. (A legal separation results when spouses separate and a court rules on the division of property, alimony, child support, custody, and visitation, but does not grant a divorce.)
Second, don't wait too long. You need to file the self-petition (called an "I-360, Petition for Amerasian, Widow(er), or Special Immigrant") within two years of the date your spouse died.
Finally, it's best to file the self-petition before you get remarried. If you marry another U.S. citizen, you won't be able to self-petition on the basis of your marriage to the spouse who died. Of course you can have your new spouse petition for you, but you might find it quicker, easier, and less expensive to file a self-petition before getting remarried.
If your spouse filed an I-130 petition for you but died before USCIS could rule on it, or if you had an application for adjustment of status (based on an approved I-130) pending (awaiting USCIS decision) at the time of your spouse's death, USCIS will still go through with your case. (See "Applying for Adjustment of Status as the Widow(er) of a U.S. Citizen.")
The same is true if you are overseas and intend to use consular processing to obtain an immigrant visa and green card.
The death of your spouse doesn't excuse you from satisfying most other green card eligibility requirements, such as proving that the marriage was real (not a fraud) and that you are admissible to the United States. (See "Legal Requirements for a Marriage-Based Visa or Green Card").
One admissibility problem some people face is too many days of "unlawful presence" in the United States. (See "Consequences of Unlawful Presence in the U.S.--Three- and Ten-Year Time Bars.") If you were waiting on an I-130 petition approval when your spouse died, you don't acquire any (or any more) days of unlawful presence while you wait for USCIS to rule on your case.
You won't, however, need to worry about inadmissibility based on not having a financial sponsor file a Form I-864 Affidavit of Support on your behalf. Widow(er)s of U.S. citizens are exempt from this requirement, and should indicate this in their application by instead filing an I-864W.
If you are outside the U.S. because you were deported, but your deceased U.S. citizen spouse had filed an I-130 petition that is still pending, you can apply for an immigrant visa (green card) from outside the country.
USCIS will let you reapply if:
Nevertheless, you'd definitely want to seek a lawyer's help with this complex sort of request.