From f9b7ec8113f7cbcbb00ab085924ddf5f067b37cb Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:46:52 +0530 Subject: [PATCH] Create 2109. Adding Spaces to a String --- 2109. Adding Spaces to a String | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 2109. Adding Spaces to a String diff --git a/2109. Adding Spaces to a String b/2109. Adding Spaces to a String new file mode 100644 index 0000000..3f49a61 --- /dev/null +++ b/2109. Adding Spaces to a String @@ -0,0 +1,15 @@ +class Solution { +public: + string addSpaces(string s, vector& spaces) { + int ind = 0; + string ans = ""; + for (int i = 0; i < s.size(); i++) { + if (ind < spaces.size() && i == spaces[ind]) { + ans += " "; + ind++; + } + ans += s[i]; + } + return ans; + } +};