---
# System prepended metadata

title: 6300. Minimum Common Value
tags: [Leetcode]

---

<style>
    html, body, .ui-content {
    background: #222222;
    color: #00BFFF;
}
    /* 設定 code 模板 */
    .markdown-body code,
.markdown-body tt {
    background-color: #ffffff36;
}
.markdown-body .highlight pre,
.markdown-body pre {
    color: #ddd;
    background-color: #00000036;
}
.hljs-tag {
    color: #ddd;
}
.token.operator {
  background-color: transparent;
}    
/* 設定連結 */
a,
.open-files-container li.selected a {
    color: #89FFF8;
    
}
a:hover,
.open-files-container li.selected a:hover {
    color: #89FFF890;
}
   
</style>

###### tags: `Leetcode`

# 6300. Minimum Common Value

###### Link : https://leetcode.com/contest/biweekly-contest-96/problems/minimum-common-value/

## 題目
回傳兩陣列最小相同數值
## 程式碼
```cpp=
class Solution {
public:
    int getCommon(vector<int>& nums1, vector<int>& nums2) {
        int a = 0, b = 0;
        while(true){
            if(a >= nums1.size() || b >= nums2.size())
                break;
            if(nums1[a] == nums2[b])
                return nums1[a];
            else if(nums1[a] < nums2[b])
                a++;
            else
                b++;
        }
        return -1;
    }
};
```
## Date 
### 2023/1/21