-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution_EasyArray.java
More file actions
96 lines (92 loc) · 2.35 KB
/
Copy pathSolution_EasyArray.java
File metadata and controls
96 lines (92 loc) · 2.35 KB
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
/**
* @Title: Solution_EasyArray.java——
* @Package EasyCode_01
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年3月27日 下午5:14:36
* @version V1.0
*/
package EasyCode_01;
import java.util.Arrays;
/**
* @ClassName: Solution_EasyArray——
* @Description: TODO
* @author msdumin@gmail.com
* @date 2019年3月27日 下午5:14:36
*/
public class Solution_EasyArray {
//977
public int[] sortedSquares(int[] A) {
int twice ;
for (int i = 0; i < A.length; i++) {
twice = A[i] * A[i];
A[i] = twice;
}
Arrays.sort(A);
return A;
}
//832
public static int[][] flipAndInvertImage(int[][] A) {
//暴力循环
// int res[][] = new int[A.length][];
for (int i = 0; i < A.length; i++) {
int len = A[i].length;
for(int j = 0 ; j < len / 2 ; j ++){
int tmp = A[i][j];
A[i][j] = A[i][len - 1 - j];
A[i][len - 1 - j] = tmp;
}
for(int j = 0 ; j < len ; j++){
if(A[i][j] == 0)
A[i][j] = 1;
else {
A[i][j] = 0;
}
}
}
return A;
}
/* //925 其实建表这个方法是行不通的....
public boolean isLongPressedName(String name, String typed) {
//建个表
int[] table_name = new int[26];
int[] table_typed = new int[26];
char[] arr1 = name.toCharArray();
char[] arr2 = typed.toCharArray();
for (int i = 0; i < arr1.length; i++) {
table_name[arr1[i] - 'a'] ++ ;
}
for (int i = 0; i < arr2.length; i++) {
table_typed[arr2[i] - 'a'] ++ ;
}
for(int i = 0 ; i < table_name.length ; i ++){
if(table_name[i] != 0){
if(table_typed[i] < table_name[i])
return false;
}
}
return true;
}*/
//925
public boolean isLongPressedName(String name, String typed){
for(int i = 0, j=0; i < name.length(); ){
if(j >= typed.length()){
return false;
}
if(name.charAt(i) == typed.charAt(j)){
i++;
j++;
}else if(i >= 1 && name.charAt(i - 1) == typed.charAt(j)) {
j++;
}else{
return false;
}
}
return true;
}
public static void main(String[] args) {
int[][] A = {{1,1,0},{1,0,1},{0,0,0}};
A = flipAndInvertImage(A);
System.out.println(" d ");
}
}