5.16 学习记录
項目學習
在打包時,通過-P XXX指令,指定打入jar的配置環境
在Pom中的profiles profile 標簽下 如:
<id> dev </id> <properties></profiles> <profiles.active>dev<profiles.active> <activeProfile>dev</activeProfile> <logLevel>info</logLevel> <properties> <activation> <activeByDefault> true </activeByDefault> </activation> 復制代碼與配置文件application-dev.yml對應,若在打包時的指令為-P dev 則會將其配置進去
fourinone分布式系統開發
個人任務:分布式調度模塊的開發 參考yarn
本周任務:學習yarn和fourinone相關模塊代碼,確定api接口
每日一題
題目:給定一個包括 n 個整數的數組 nums 和 一個目標值 target。找出 nums 中的三個整數,使得它們的和與 target 最接近。返回這三個數的和。假定每組輸入只存在唯一答案。
例如,給定數組 nums = [-1,2,1,-4], 和 target = 1. 與 target 最接近的三個數的和為 2. (-1 + 2 + 1 = 2).
思路
首先將原數組排序,成為一個有序數組。
因為是三數之和,所以遍歷數組確定第一個數,成為哨兵,用兩個指針表示第二個數和第三個數。
兩個指針初始分別指向除哨兵外最小的數和最大的數(也就是最左邊和最右邊),當左指針下標小于右指針時進行循環,計算三數之和,如果三數之和比結果值更接近target,則更新target。若三數之和小于taget,則將左指針向右移;反之則將右指針向左移。當然如果和恰好等于target,直接返回target。
代碼
public static int threeSumClosest(int[] nums, int target) {Arrays.sort(nums);int result = nums[0] + nums[1] + nums[2];for(int i = 0; i< nums.length-2; i++) {int l = i+1;int r = nums.length - 1 ;while( l < r) {int threeNum = nums[i] + nums[l] +nums[r];if(Math.abs(threeNum - target) < Math.abs(result - target)) {result = threeNum;}if(threeNum < target) {l++;} else if(threeNum > target) {r--;} else return target;}}return result;} 復制代碼轉載于:https://juejin.im/post/5cdd00d3e51d453ce71f6117
總結
- 上一篇: 利用Python3内置文档资源高效学习及
- 下一篇: Java反射机制大神必学系列之 ,高级与