A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d9/d80/trapped__rainwater_8cpp_source.html below:

TheAlgorithms/C++: dynamic_programming/trapped_rainwater.cpp Source File

Go to the documentation of this file. 28

std::size_t n = heights.size();

32

std::vector<uint32_t> leftMax(n), rightMax(n);

35

leftMax[0] = heights[0];

36 for

(std::size_t i = 1; i < n; ++i) {

37

leftMax[i] = std::max(leftMax[i - 1], heights[i]);

41

rightMax[n - 1] = heights[n - 1];

42 for

(std::size_t i = n - 2; i < n; --i) {

43

rightMax[i] = std::max(rightMax[i + 1], heights[i]);

47

uint32_t trappedWater = 0;

48 for

(std::size_t i = 0; i < n; ++i) {

50

std::max(0u, std::min(leftMax[i], rightMax[i]) - heights[i]);

63

std::vector<uint32_t> test_basic = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1};

66

std::vector<uint32_t> test_peak_under_water = {3, 0, 2, 0, 4};

69

std::vector<uint32_t> test_bucket = {5, 1, 5};

72

std::vector<uint32_t> test_skewed_bucket = {4, 1, 5};

75

std::vector<uint32_t> test_empty = {};

78

std::vector<uint32_t> test_flat = {0, 0, 0, 0, 0};

81

std::vector<uint32_t> test_no_trapped_water = {1, 1, 2, 4, 0, 0, 0};

84

std::vector<uint32_t> test_single_elevation = {5};

87

std::vector<uint32_t> test_two_point_elevation = {5, 1};

91

std::vector<uint32_t> test_large_elevation_map_difference = {5, 1, 6, 1,

94

test_large_elevation_map_difference) == 15);

Dynamic Programming algorithms.

uint32_t trappedRainwater(const std::vector< uint32_t > &heights)

Function to calculate the trapped rainwater.

static void test()

Self-test implementations.

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4