0
点赞
收藏
分享

微信扫一扫

ICLR2024: 大视觉语言模型中对象幻觉的分析和缓解

书写经典 2024-09-07 阅读 22

题目:

题解:

class Solution {
public:
    int firstUniqChar(string s) {
        unordered_map<char, int> position;
        queue<pair<char, int>> q;
        int n = s.size();
        for (int i = 0; i < n; ++i) {
            if (!position.count(s[i])) {
                position[s[i]] = i;
                q.emplace(s[i], i);
            }
            else {
                position[s[i]] = -1;
                while (!q.empty() && position[q.front().first] == -1) {
                    q.pop();
                }
            }
        }
        return q.empty() ? -1 : q.front().second;
    }
};
举报

相关推荐

0 条评论