Skip to content

Instantly share code, notes, and snippets.

@shitu13
Created May 28, 2024 17:50
Show Gist options
  • Save shitu13/61b295bce5eb8dcaa39b7656bc8e614e to your computer and use it in GitHub Desktop.
Save shitu13/61b295bce5eb8dcaa39b7656bc8e614e to your computer and use it in GitHub Desktop.
Find Target Indices After Sorting Array
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