I was solving the problem :1732D1 - Balance (Easy version). And my solution was same as i keep the track of thekth-MEXof thexthelement when ever the request has been made. So for checking whether the kth element is present in the set or not, i usedunordered_map<>by while adding ...
stringkey; // each node stores a map to its child nodes unordered_map<char,Trie*>character; }; // Data structure to store a heap node structNode { stringkey; intcount; }; // Comparison object used to order the max-heap structcomp { booloperator()(constNode&lhs,constNode&rhs)const{...
Complexity Up to linear in the distance between first and last: Calls pred for each element until a match is found.Data races Some (or all) of the objects in the range [first,last) are accessed (once at most).Exceptions Throws if either pred or an operation on an iterator throws. ...
unordered_map<int,int>parent; public: // perform MakeSet operation voidMakeSet(intn) { // create `n` disjoint sets (one for each vertex) for(inti=0;i<n;i++){ parent[i]=i; } } // Find the root of the set in which element `k` belongs intFind(intk) { // if `k` is ro...
Your runtime complexity should be less than O(n2). There is only one duplicate number in the array, but it could be repeated more than once. Runtime: 28ms 1 class Solution { 2 public: 3 int findDuplicate(vector<int>& nums) { 4 if(nums.empty()) return 0; 5 6 unordered_map<int...
class Solution { public: vector<vector<string>> findDuplicate(vector<string>& paths) { unordered_map<string, vector<string>> m; vector<vector<string>> res; for (string& path : paths) { istringstream is(path); string pre = "", t = ""; is >> pre; while (is >> t) { int idx ...
// string::find_first_of#include <iostream>// std::cout#include <string>// std::string#include <cstddef>// std::size_tintmain () { std::string str ("Please, replace the vowels in this sentence by asterisks."); std::size_t found = str.find_first_of("aeiou");while(found!=std...
class Solution {public: vector> findDuplicate(vector& paths) { vector> res; unordered_map> m; for(string path:paths){ istringstream is(path); string pre="",t=""; is>>pre; while(is>>t){ int idx=t.find_last_of('('); string dir=pre+"/"+t.substr(0,idx); string content=t.su...
for path in paths: roads = path.split() directory, files = roads[0], roads[1:] for file in files: file_s = file.split('(') name, content = file_s[0], file_s[1][:-1] full = directory + '/' + name filemap[content].append(full) ...
// Running time: 80ms (beats 94.68%) class Solution { public: vector<vector<string>> findDuplicate(vector<string>& paths) { unordered_map<string, vector<string>> files; // content -> filenames for (const string& path : paths) { string folder; int i = 0; while (path[i] != ' ...