File tree Expand file tree Collapse file tree 6 files changed +128
-0
lines changed Expand file tree Collapse file tree 6 files changed +128
-0
lines changed Original file line number Diff line number Diff line change
1
+ vector<bool > kidsWithCandies (vector<int >& candies, int extraCandies) {
2
+ int len = candies.size ();
3
+ int maxmum = candies[0 ];
4
+ for (int i = 1 ; i < len; ++i)
5
+ {
6
+ if (candies[i] > maxmum)
7
+ maxmum = candies[i];
8
+ }
9
+
10
+ vector<bool > res (len);
11
+ for (int i = 0 ; i < len; ++i)
12
+ {
13
+ if (candies[i]+extraCandies >= maxmum)
14
+ res[i] = true ;
15
+ }
16
+
17
+ return res;
18
+ }
Original file line number Diff line number Diff line change
1
+ string destCity (vector<vector<string>>& paths) {
2
+ map<string, int > mp;
3
+ int len = paths.size ();
4
+ for (int i = 0 ; i < len; ++i)
5
+ {
6
+ if (mp.find (paths[i][0 ]) == mp.end ())
7
+ mp[paths[i][0 ]] = -1 ;
8
+ else
9
+ mp[paths[i][0 ]] = 0 ;
10
+ if (mp.find (paths[i][1 ]) == mp.end ())
11
+ mp[paths[i][1 ]] = 1 ;
12
+ else
13
+ mp[paths[i][1 ]] = 0 ;
14
+ }
15
+
16
+ for (auto iter = mp.begin (); iter != mp.end (); ++iter)
17
+ if (iter->second == 1 )
18
+ return iter->first ;
19
+
20
+ return " " ;
21
+ }
Original file line number Diff line number Diff line change
1
+ vector<string> buildArray (vector<int >& target, int n) {
2
+ vector<string> res (n*2 );
3
+ int len = target.size ();
4
+ int last = 0 ;
5
+ int ct = 0 ;
6
+ for (int i = 0 ; i < len; ++i)
7
+ {
8
+ int tmp = target[i]-last-1 ;
9
+ if (tmp == 0 )
10
+ res[ct++] = " Push" ;
11
+ else
12
+ {
13
+ for (int j = 0 ; j < tmp; ++j)
14
+ {
15
+ res[ct] = " Push" ;
16
+ res[ct+1 ] = " Pop" ;
17
+ ct += 2 ;
18
+ }
19
+ res[ct++] = " Push" ;
20
+ }
21
+ last = target[i];
22
+ }
23
+
24
+ res.resize (ct);
25
+ return res;
26
+ }
Original file line number Diff line number Diff line change
1
+ int maxPower (string s) {
2
+ int len = s.size ();
3
+ int maxmum = 1 ;
4
+
5
+ char c = s[0 ];
6
+ int i = 1 , ct = 1 ;
7
+ while (i < len)
8
+ {
9
+ if (s[i] == c)
10
+ ++ct;
11
+ else
12
+ {
13
+ if (ct > maxmum)
14
+ maxmum = ct;
15
+ ct = 1 ;
16
+ c = s[i];
17
+ }
18
+
19
+ ++i;
20
+ }
21
+
22
+ if (ct > maxmum)
23
+ maxmum = ct;
24
+
25
+ return maxmum;
26
+ }
Original file line number Diff line number Diff line change
1
+ int goodNodes (TreeNode* root) {
2
+ if (root == nullptr )
3
+ return 0 ;
4
+ int ct = 1 ;
5
+ int maxmum = root->val ;
6
+
7
+ if (root->left != nullptr )
8
+ search (root->left , maxmum, ct);
9
+ if (root->right != nullptr )
10
+ search (root->right , maxmum, ct);
11
+
12
+ return ct;
13
+ }
14
+
15
+ void search (TreeNode* node, int maxmum, int & ct)
16
+ {
17
+ if (node->val >= maxmum)
18
+ {
19
+ ++ct;
20
+ maxmum = node->val ;
21
+ }
22
+ if (node->left != nullptr )
23
+ search (node->left , maxmum, ct);
24
+ if (node->right != nullptr )
25
+ search (node->right , maxmum, ct);
26
+ }
Original file line number Diff line number Diff line change
1
+ int busyStudent (vector<int >& startTime, vector<int >& endTime, int queryTime) {
2
+ int len = startTime.size ();
3
+ int ct = 0 ;
4
+ for (int i = 0 ; i < len; ++i)
5
+ {
6
+ if (queryTime >= startTime[i] && queryTime <= endTime[i])
7
+ ++ct;
8
+ }
9
+
10
+ return ct;
11
+ }
You can’t perform that action at this time.
0 commit comments