2395. Find Subarrays With Equal Sum
2023. 1. 24. 13:40ㆍAlgorithm/Leetcode, Lintcode, HackerRank, etc.
- 목차
반응형
Python
class Solution:
def findSubarrays(self, nums: List[int]) -> bool:
n = len(nums)
if n < 2:
return False
for i in range(n - 1):
tot = nums[i] + nums[i + 1]
for j in range(i + 1, n - 1):
if tot == nums[j] + nums[j + 1]:
return True
return False
Kotlin
class Solution {
fun findSubarrays(nums: IntArray): Boolean {
val n: Int = nums.size
if (n < 2) {
return false
}
for (i in 0 until n - 1) {
val tot: Int = nums[i] + nums[i + 1]
for (j in i + 1 until n - 1) {
if (tot == nums[j] + nums[j + 1]) {
return true
}
}
}
return false
}
}
C++
class Solution {
public:
bool findSubarrays(vector<int>& nums) {
int n = nums.size();
if (n < 2) {
return false;
}
for (auto i = 0; i < n - 1; ++i) {
int tot = nums[i] + nums[i + 1];
for (auto j = i + 1; j < n - 1; ++j) {
if (tot == nums[j] + nums[j + 1]) {
return true;
}
}
}
return false;
}
};
반응형
'Algorithm > Leetcode, Lintcode, HackerRank, etc.' 카테고리의 다른 글
2269. Find the K-Beauty of a Number (0) | 2023.01.26 |
---|---|
2389. Longest Subsequence With Limited Sum (0) | 2023.01.24 |
2405. Optimal Partition of String (0) | 2023.01.24 |
2410. Maximum Matching of Players With Trainers (0) | 2023.01.07 |
2409. Count Days Spent Together (0) | 2023.01.07 |