2022年3月15日 星期二

LeetCode 13. Roman to Integer


題目是將羅馬文字轉成數字
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
Given a roman numeral, convert it to an integer.

LeetCode 1. Two Sum

 https://leetcode.com/problems/two-sum/


題目是Input是一個陣列,且沒有排序,需要將兩數相加,回傳該兩數的位置,且兩個位置不能相同。
範例:
Example 1:

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2:

Input: nums = [3,2,4], target = 6
Output: [1,2]

Example 3:

Input: nums = [3,3], target = 6
Output: [0,1]

解題:

LeetCode 14. Longest Common Prefix

https://leetcode.com/problems/longest-common-prefix/
題目:

Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"

Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.


Constraints:
  • 1 <= strs.length <= 200
  • 0 <= strs[i].length <= 200
  • strs[i] consists of only lower-case English letters.

2021年10月28日 星期四

Android Studio 聊天室下拉加載歷史訊息

 一開始需求是每次有新的訊息要在最下面

然後就很突然的,將 RecyclerView 設置為倒序

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), 
LinearLayoutManager.VERTICAL, true); // 列表翻轉
linearLayoutManager.setStackFromEnd(true); // 列表在底部開始展示, 反轉後由上面開始展示
rvMessagesChat.setLayoutManager(linearLayoutManager);
rvMessagesChat.setHasFixedSize(true);
rvMessagesChat.setAnimation(null);


但是在加載新資料的時候,舊資料會被擠下去

int beforeSize = mList.size();
int afterSize = model.vModelRecord.size();
profileMessagesChatAdapter.addList(model.vModelRecord);
profileMessagesChatAdapter.notifyItemRangeInserted(beforeSize, afterSize);


所以需要新增這行,這樣就不會有擠壓的動畫

rvMessagesChat.setAnimation(null);

2021年9月15日 星期三

Samba - Ubunta 和 Windows 之間的橋樑

 1. 先在 Ubunta 安裝 Samba 

sudo apt-get install samba


2. 設定 Samba 工作群組,要和Windows 相同

 vim /etc/samba/smb.conf

3. 設定要分享的資料夾,格式如下

[ShareName] 分享資料夾名稱

path = /var/usr/    分享資料夾路徑

read only = no    是否唯讀

create mask = 777     檔案遮罩

directory mask = 777    資料夾遮至

writable = yes    是否可寫入

4. 將 Samba 加進防火牆白名單

sudo ufw status verbose → 確認防火牆狀態

sudo ufw allow samba → 將 Samba 加進防火牆白名單

sudo ufw reload → 重啟防火牆

5. 重啟 Samba 讓他吃修改後的設定檔

sudo service smbd restart

6. 完成

2021年8月25日 星期三

AppsFlyer 廣告追蹤

 Apps Flyer 是一個多平台整合的廣告追蹤網站


Apps Flyer 相關

Android SDK 集成

iOS SDK 集成


Facebook 相關

Facebook 廣告配置指南

Facebook SDK

Facebook Dashboard



iOS 14.5 官方將廣告追蹤透明化

必須經過用戶同意方可進行追蹤

再設定 Facebook 追蹤時,

必須將事件管理工具 > 資料來源 > 設定 > 為 SKAdNetwork 設定應用程式事件 開啟

並編輯事件,才可以收到來自 iOS 的資料


Swift 

AppEvents.logEvent(AppEvents.Name.completedRegistration)


Android Studio IDE 錯誤

 :app:compile xxxxx JavaWithJavac FAILED An exception has occurred in the compiler (1.8.0_312). Please file a bug against the Java compiler ...