Я пытался решить проблему Leetcode №697: степень массива. Я создал карту для хранения значений . Я видел примеры, когда люди использовали строки element.first и element. Second для получения значений, хранящихся на карте. Однако я получаю сообщение об ошибке, сообщающее, что на карте нет элемента с именем Second. Я хочу знать, существует ли встроенная функция для получения второго элемента с карты и есть ли стандартный способ сделать это.
class Solution {
public:
int findShortestSubArray(vector& nums) {
//nums -> array of integers
// step 1 : iterate through the array and find the degree, I would do this by iterating through nums and storing the value of each number in a hashmap
// The hash map will store the number, first occ and last occ
// The key will be the number and the values stored will be first and sec occurance.
unordered_map firstOcc;
unordered_map secondOcc;
unordered_map count;
// Go through the array and collect the first/last occ and the frequency
for (int i =0; i
Подробнее здесь: https://stackoverflow.com/questions/791 ... -map-value