online_judge
, c
給定一個已排序的 int 陣列, 要求移除陣列內出現數超過兩次的元素, 同時要求 O(1) 空間複雜度。
難度不高的 Medium 題目, 但需要注意邊界問題。
由於給定的陣列有經過排序, 因此只需要和上一個元素作比對, 而不必對整個陣列作搜尋。
發現同樣的元素時, 則把 flag 改為 true, 若 flag 已經為 true, 則代表元素已經出現超過兩次。可以跳過該元素。
注意給定陣列大小可為 0, 需要進行例外處理。
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
int removeDuplicates(int* nums, int numsSize){
if(numsSize<1){
return numsSize;
}
int count = 1;
int hit = 0;
int i;
for(i = 1; i < numsSize; i++){
if(nums[count-1] == nums[i]){
if(hit == 1){
continue;
}
hit = 1;
}
else{
hit = 0;
}
nums[count] = nums[i];
count++;
}
return count;
}
Learn More →
tmux 的全稱是 Terminal Multiplexer,直譯過來就是終端(Terminal)多工器(Multiplexer),這個工具可以在單一 screen 之下 create, attach, detach 多個終端,熟悉之後十分好用。只是和 vim,vi 系列相同,所有操作皆能且只能使用鍵盤,不像 GNOME Terminal 一樣有直觀的 GUI 介面,算不上友善的學習曲線使人又愛又恨。關於 tmux 的基本概念和入門組合鍵,G. T. Wang 的文章提供了很不錯的繁體中文資料,本篇的重點在於如何配合 shell script 和 tmux 來快速建立一個順手的工作區。
Sep 18, 2024轉眼就在日本工作快半年了,想說就來整理一下求職當下的記錄吧。先說一下小弟我的狀況,原本其實是沒有來日本工作的計劃,打算就老老實實GG輪班救台灣的。只是剛好修個日文課,剛好老師介紹下參加了幾場面試,誤打誤撞的就拿到了還算可以的內定。瞄著日本的綠卡傻傻的就跑來了。所以說人生啊,緣分真的很重要。而計劃,永遠趕不上變化。
May 31, 2024Introduction
Jun 21, 2023Revision record version comment author v0.1.0 document built Marco Ma
Jan 20, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up