發表文章

[C++] LeeCode 7. Reverse Integer

Language Information : C++ Description : Reverse Integer URL :  https://leetcode.com/problems/reverse-integer/ Code : class Solution { public: int reverse(long long int x) { long long int sum = 0; long long int num = abs(x); vector<int> vec; while(num>0){ long long int temp = num%10; vec.push_back(temp); num = num/10; } for(int i=0;i<vec.size();i++){ sum += vec[i]*pow(10,vec.size()-i-1); } if(x<0){ sum = 0-sum; } if(sum < INT_MIN || sum > INT_MAX){ return 0; }else{ return (int)sum; } } }; - 使用迴圈去%10並存入vector, 在使用迴圈反過來乘上十的N次方, 要注意負數, 再來要注意到此題要求最終答案小於int的範圍要回傳0。

[C++] LeeCode 1. Two Sum

Language Information : C++ Description : Two Sum URL :  https://leetcode.com/problems/two-sum/ Code : class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> vec; for(int i=0;i<nums.size();i++){ for(int j=i+1;j<nums.size();j++){ if(target-nums[i]==nums[j]){ vec.push_back(i); vec.push_back(j); break; } } } return vec; } }; - 宣告一個 arrayList  = []去存結果, 使用最外層的 for loop 巡 nums 這個 input list, 宣告參數 subSum 讓 target 減去正在被巡的for element, 使用內層 for loop 再次巡 nums 並找出是否還有相減後相符的數字, 找到後將其位置 append 至 arrayList, 若未找到則將 subSum 歸零,重新繼續尋找。

[Python] LeeCode 1. Two Sum

Language Information : Python3 Description : Two Sum URL :  https://leetcode.com/problems/two-sum/ Code : class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: arrayList = [] for i in range(len(nums)): subSum = target - nums[i] for x in range(i,len(nums)): if x==i: continue elif subSum == nums[x]: arrayList.append(i) arrayList.append(x) return arrayList break else: pass subSum = 0 - 宣告一個 arrayList  = []去存結果, 使用最外層的 for loop 巡 nums 這個 input list, 宣告參數 subSum 讓 target 減去正在被巡的for element, 使用內層 for loop 再次巡 nums 並找出是否還有相減後相符的數字, 找到後將其位置 append 至 arrayList, 若未找到則將 subSum 歸零,重新繼續尋找。

[Pytorch] Pytorch torchvision.transforms 函數介紹

1.transforms.ToTensor() ToTensor()將shape(H,W,C)轉為shape(C,H,W)的tensor, 將每一個數值歸一化為[0,1], 直接將數值除255 2.transforms,Normalize() transforms.Compose([transforms.ToTensor(),transforms.Normalize(std=(0.5,0.5,0.5),mean=(0.5,0.5,0.5))]), 將輸入歸一化至[0,1], 再使用公式 (x-mean)/std, 將圖片的三通到分佈至[-1,1]

[MATLAB] MATLAB R2018b 安装 mexopencv (VS 2017)

安裝過程噴錯 Error using mex Unknown MEX argument '-R2017b-largeArrayDims'. Error in mexopencv.make (line 97) if ~opts.dryrun, eval(cmd); end 解決方法,去make.m的第275~281行,註解掉 % real/imaginary storage format for complex arrays if ~mexopencv.isOctave() && ~verLessThan('matlab', '9.4') % keep using the "separate complex storage", as opposed to the % "interleaved complex storage" introduced in R2018a % (see MX_HAS_INTERLEAVED_COMPLEX) %mex_flags = ['-R2017b' mex_flags]; end

[Windows] Windows 在 cmd 輸入 ls 命令處理, 解決 'ls' 不是內部或外部命令、可執行的程式或批次檔。

在windows 的 cmd 下 ls 會出現 'ls' 不是內部或外部命令、可執行的程式或批次檔。 解決方法 : 在C:/Windows下新增 'ls.bat',內容為 : @echo off dir 完成!

[CentOS, OpenCV] CentOS 7 安裝 OpenCV 3.4.5 (CentOS install OpenCV )

先下載OpenCV,版本自選,應該會得到xxx.zip - 安裝相關套件 $yum install cmake $yum install gcc gcc-c++ kernel-devel gcc-essential gcc-gfortran $yum install git ibgnomeui-devel gtk2 gtk2-devel gtk2-devel-docs - 確認自己有沒有pkg-config --version ,我是使用 0.27.1,沒有的話自行裝一下 - 安裝epel擴展及其他相關擴展 $yum -y install epel-release $yum localinstall –nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm $yum localinstall –nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm - 安裝ffmpeg-deve $yum -y install ffmpeg ffmpeg-devel $ffmpeg -version - 安裝opencv其他依賴 $yum install python-devel numpy $yum install libdc1394-devel $yum install libv4l-devel $yum install gstreamer-plugins-base-devel - Cmake編譯 $cd opencv $mkdir build $cd build $cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..  $cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..  $cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_op...