Sentinel-2 NDVI and surface reflectance time series have been widely used in various geoscience research, but the data is deteriorated or missing due to the cloud contamination, so it is necessary to reconstruct the Sentinel-2 NDVI and surface reflectance time series. At present, there are few studies on reconstructing the Sentinel-2 NDVI or surface reflectance time series, and these existing reconstruction methods have some shortcomings. We proposed a new method to reconstruct the Sentinel-2 NDVI and surface reflectance time series using the penalized least-square regression based on discrete cosine transform (DCT-PLS) method. This method iteratively identifies cloud-contaminated NDVI over NDVI time series from the Sentinel-2 surface reflectance data by adjusting the weights. The NDVI and surface reflectance time series are then reconstructed from cloud-free NDVI and surface reflectance using the adjusted weights as constraints. We have made some improvements to the DCT-PLS method. First, the traditional discrete cosine transformation (DCT) in the DCT-PLS method is matrix generated from discrete and equally spaced data, we reconfigured the DCT formulas to adapt for irregular interval time series, and optimized the control parameters N and s according to the typical vegetation samples in China. Second, the DCT-PLS method was deployed in the Google Earth Engine (GEE) platform for the efficiency and convenience of data users. We used the DCT-PLS method to reconstruct the Sentinel-2 NDVI time series and surface reflectance time series in the blue, green, red, and near infrared (NIR) bands in typical vegetation samples and the Zhangjiakou and Hangzhou study area. We found that this method performed better than the SG filter method in reconstructing the NDVI time series, and can identify and reconstruct the contaminated NDVI as well as surface reflectance with low root mean square error (RMSE) and high coefficient of determination (R2). However, in cases of a long range of cloud contamination, or above water surface, it may be necessary to increase the control parameter s for a more stable performance. The GEE code is freely available online and the link is in the conclusions of this article, researchers are welcome to use this method to generate cloudless Sentinel-2 NDVI and surface reflectance time series with 10 m spatial resolution, which is convenient for landcover classification and many other types of research.