-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay61
122 lines (100 loc) · 3.08 KB
/
Day61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//A. In Search of an Easy Problem
import java.util.Scanner;
public class EasyProblem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
boolean isHard = false;
for (int i = 0; i < n; i++) {
int opinion = scanner.nextInt();
if (opinion == 1) {
isHard = true;
break;
}
}
if (isHard) {
System.out.println("HARD");
} else {
System.out.println("EASY");
}
}
}
//George and Accommodation
//https://codeforces.com/problemset/problem/467/A
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int count = 0;
for (int i = 0; i < n; i++) {
int p = scanner.nextInt();
int q = scanner.nextInt();
if (q - p >= 2) {
count++;
}
}
System.out.println(count);
scanner.close();
}
}
//1886. Determine Whether Matrix Can Be Obtained By Rotation
//https://leetcode.com/problems/determine-whether-matrix-can-be-obtained-by-rotation/description/
class Solution {
public boolean findRotation(int[][] a, int[][] b) {
int n=a.length;
int c90=0,c180=0,c270=0,c0=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(b[i][j]==a[n-j-1][i])
c90++;
if(b[i][j]==a[n-i-1][n-j-1])
c180++;
if(b[i][j]==a[j][n-i-1])
c270++;
if(b[i][j]==a[i][j])
c0++;
}
}
if(c90==n*n||c270==n*n||c180==n*n||c0==n*n)
return true;
else return false;
}
}
//1304. Find N Unique Integers Sum up to Zero
//https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/
class Solution {
public int[] sumZero(int n) {
int[] res = new int[n]; // Create an array of size n
// If n is odd, add 0 to the result
if (n % 2 != 0) {
res[n / 2] = 0; // Place 0 in the middle
}
// Add pairs of integers
for (int i = 1; i <= n / 2; i++) {
res[i - 1] = i; // Positive integer
res[n - i] = -i; // Corresponding negative integer
}
return res; // Return the result array
}
}
//53. Maximum Subarray
//https://leetcode.com/problems/maximum-subarray/description/
class Solution {
public int maxSubArray(int[] nums) {
int maxSum = Integer.MIN_VALUE;
int currentSum = 0;
for (int i = 0; i < nums.length; i++) {
currentSum += nums[i];
if (currentSum > maxSum) {
maxSum = currentSum;
}
if (currentSum < 0) {
currentSum = 0;
}
}
return maxSum;
}
}