Skip to content

Commit

Permalink
➕2748
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcaffebabe committed Jun 20, 2024
1 parent 67251af commit 16a4d09
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@
2733 | [2733.既不是最小值也不是最大值](/%E7%AE%97%E6%B3%95/2501-3000/2733.%E6%97%A2%E4%B8%8D%E6%98%AF%E6%9C%80%E5%B0%8F%E5%80%BC%E4%B9%9F%E4%B8%8D%E6%98%AF%E6%9C%80%E5%A4%A7%E5%80%BC/2733.%E6%97%A2%E4%B8%8D%E6%98%AF%E6%9C%80%E5%B0%8F%E5%80%BC%E4%B9%9F%E4%B8%8D%E6%98%AF%E6%9C%80%E5%A4%A7%E5%80%BC.java)
2740 | [2740.找出分区值](/%E7%AE%97%E6%B3%95/2501-3000/2740.%E6%89%BE%E5%87%BA%E5%88%86%E5%8C%BA%E5%80%BC/2740.%E6%89%BE%E5%87%BA%E5%88%86%E5%8C%BA%E5%80%BC.java)
2744 | [2744.最大字符串配对数目](/%E7%AE%97%E6%B3%95/2501-3000/2744.%E6%9C%80%E5%A4%A7%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%85%8D%E5%AF%B9%E6%95%B0%E7%9B%AE/2744.%E6%9C%80%E5%A4%A7%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%85%8D%E5%AF%B9%E6%95%B0%E7%9B%AE.java)
2748 | [2748.美丽下标对的数目](/%E7%AE%97%E6%B3%95/2501-3000/2748.%E7%BE%8E%E4%B8%BD%E4%B8%8B%E6%A0%87%E5%AF%B9%E7%9A%84%E6%95%B0%E7%9B%AE/2748.%E7%BE%8E%E4%B8%BD%E4%B8%8B%E6%A0%87%E5%AF%B9%E7%9A%84%E6%95%B0%E7%9B%AE.java)
2765 | [2765.最长交替子数组](/%E7%AE%97%E6%B3%95/2501-3000/2765.%E6%9C%80%E9%95%BF%E4%BA%A4%E6%9B%BF%E5%AD%90%E6%95%B0%E7%BB%84/2765.%E6%9C%80%E9%95%BF%E4%BA%A4%E6%9B%BF%E5%AD%90%E6%95%B0%E7%BB%84.java)
2769 | [2769.找出最大的可达成数字](/%E7%AE%97%E6%B3%95/2501-3000/2769.%E6%89%BE%E5%87%BA%E6%9C%80%E5%A4%A7%E7%9A%84%E5%8F%AF%E8%BE%BE%E6%88%90%E6%95%B0%E5%AD%97/2769.%E6%89%BE%E5%87%BA%E6%9C%80%E5%A4%A7%E7%9A%84%E5%8F%AF%E8%BE%BE%E6%88%90%E6%95%B0%E5%AD%97.java)
2778 | [2778.特殊元素平方和](/%E7%AE%97%E6%B3%95/2501-3000/2778.%E7%89%B9%E6%AE%8A%E5%85%83%E7%B4%A0%E5%B9%B3%E6%96%B9%E5%92%8C/2778.%E7%89%B9%E6%AE%8A%E5%85%83%E7%B4%A0%E5%B9%B3%E6%96%B9%E5%92%8C.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* @lc app=leetcode.cn id=2748 lang=java
* @lcpr version=
*
* [2748] 美丽下标对的数目
*
* 3005/3005 cases passed (30 ms)
* Your runtime beats 13.18 % of java submissions
* Your memory usage beats 90.91 % of java submissions (43.2 MB)
*/


// @lcpr-template-start

// @lcpr-template-end
// @lc code=start
class Solution {
public int countBeautifulPairs(int[] nums) {
int ans = 0;
for(int i = 0; i < nums.length - 1; i++) {
for(int j = i + 1; j < nums.length; j++) {
int a = getFirst(nums[i]);
int b = getLast(nums[j]);
if (gcd(a, b) == 1) ans++;
}
}
return ans;
}

int getFirst(int a) {
if (a >= 0 && a < 10) return a;
if (a >= 10 && a < 100) return a / 10;
if (a >= 100 && a < 1000) return a / 100;
if (a >= 1000 && a < 10000) return a / 1000;
return -1;
}

int getLast(int a) {
if (a >= 0 && a < 10) return a;
if (a >= 10 && a < 100) return a % 10;
if (a >= 100 && a < 1000) return getLast(a % 100);
if (a >= 1000 && a < 10000) return getLast(a % 1000);
return -1;
}

int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
}
// @lc code=end



/*
// @lcpr case=start
// [2,5,1,4]\n
// [532,522,353,691,2441,2082,2477,2293,1449,268,2141,203,523,1063,1259,79,2419,1081,1224,1204,1933,179,1579,917,2355,702,1653,356,909,1763,1107,1277,284,1668,2453,233,1367,1714,276,1369,496,1609,2429,206,504,594,1428]\n
// @lcpr case=end
// @lcpr case=start
// [11,21,12]\n
// @lcpr case=end
*/

0 comments on commit 16a4d09

Please sign in to comment.