Created
May 28, 2024 17:50
-
-
Save shitu13/61b295bce5eb8dcaa39b7656bc8e614e to your computer and use it in GitHub Desktop.
Find Target Indices After Sorting Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> targetIndices(vector<int>& nums, int target) { | |
sort(nums.begin(), nums.end()); | |
int n = nums.size(); | |
vector<int> res; | |
for (int i = 0; i < n; i++) { | |
if (nums[i] == target) | |
res.push_back(i); | |
} | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment