— Diary, Programming — 1 min read
Yeah it's early but I thought I should complete my work on the HackOn website ASAP. Time to update the Modal, and past workshops. The most important thing is to find the data related to workshops. Since I just received the names of the workshops, I'll be going to their LinkedIn to search for content related to speaker as well as the workshop description.
Finally updated the workshop data. To get all the information was a tough job along with some UI fixes. Although I did just encountered another bug. The modal can be closed easily on the PC by clicking the backdrop but on mobile phones, the backdrop is not visible, so there is a need for a close button. I'll just reuse the add-calender
icon and rotate it to look like a cross.
Took some time to position the button in the modal with some position hacks, DAMN! But it's finally done.
Time for sleep after I watch some Lucifer!
Let's start today's Leetcode challenge. The question seems to be pretty simple. The approach is to maintain a vector that stores the distance from left, and then use that to find whether the distance is minimum from left or right, and by how much.
1vector<int> shortestToChar(string s, char c) {2 int a = 100000;3 vector<int> left, right(s.length(), 0);4 for (int i = 0; i < s.length(); i++) {5 a++;6 if (s[i] == c) {7 a = 0;8 }9 left.push_back(a);10 }11 a = 100000;12 for (int i = s.length() - 1; i >= 0; i--) {13 a++;14 if (s[i] == c) {15 a = 0;16 }17 right[i] = min(a, left[i]);18 }1920 return right;21}
The complexity is O(N)
and space complexity is O(N)
where N
is the length of the string.
Bye!