Skip to content

Commit 4d3634b

Browse files
committed
go on exercise
1 parent b6c968d commit 4d3634b

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
 /**
2+
*
3+
* 打表法
4+
*
5+
*/
6+
import java.util.Arrays;
7+
import java.util.LinkedList;
8+
import java.util.List;
9+
10+
public class FindWords
11+
{
12+
private static final String first = "qwertyuiopQWERTYUIOP";
13+
private static final String second = "asdfghjklASDFGHJKL";
14+
private static final String third = "zxcvbnmZXCVBNM";
15+
16+
public String[] findWords(String[] words)
17+
{
18+
List<String> list = new LinkedList<>();
19+
for (String word : words)
20+
{
21+
boolean isOneRow = true, isFirst = false, isSecond = false, isThird = false;
22+
23+
if (first.indexOf(word.charAt(0)) != -1)
24+
{
25+
isFirst = true;
26+
}
27+
else if (second.indexOf(word.charAt(0)) != -1)
28+
{
29+
isSecond = true;
30+
}
31+
else if (third.indexOf(word.charAt(0)) != -1)
32+
{
33+
isThird = true;
34+
}
35+
else
36+
{
37+
continue;
38+
}
39+
40+
for (char c : word.toCharArray())
41+
{
42+
if (isFirst)
43+
{
44+
if(first.indexOf(c) == -1)
45+
{
46+
isOneRow = false;
47+
}
48+
}
49+
else if (isSecond)
50+
{
51+
if(second.indexOf(c) == -1)
52+
{
53+
isOneRow = false;
54+
}
55+
}
56+
else
57+
{
58+
if(third.indexOf(c) == -1)
59+
{
60+
isOneRow = false;
61+
}
62+
}
63+
}
64+
if(isOneRow)
65+
{
66+
list.add(word);
67+
}
68+
}
69+
return list.toArray(new String[list.size()]);
70+
}
71+
72+
public static void main(String[] args)
73+
{
74+
FindWords f = new FindWords();
75+
String[] arr = new String[]{"Hello", "Alaska", "Dad", "Peace"};
76+
System.out.println(Arrays.toString(f.findWords(arr)));
77+
}
78+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
 /**
2+
*
3+
*
4+
*
5+
*/
6+
public class Solution {
7+
public String complexNumberMultiply(String a, String b) {
8+
int x1, x2, y1, y2;
9+
String[] A = a.split("\\+");
10+
String[] B = b.split("\\+");
11+
12+
x1 = Integer.valueOf(A[0]);
13+
x2 = Integer.valueOf(B[0]);
14+
y1 = Integer.valueOf(A[1].replace("i", ""));
15+
y2 = Integer.valueOf(B[1].replace("i", ""));
16+
17+
int x1x2 = x1 * x2;
18+
int y1y2 = y1 * y2;
19+
int x1y2y1x2 = x1 * y2 + x2 * y1;
20+
21+
String xfinal = x1x2 -y1y2 + "";
22+
String yfinal = x1y2y1x2 + "i";
23+
String res = xfinal + "+" + yfinal;
24+
return res;
25+
}
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
 /**
2+
*
3+
*
4+
*
5+
*/
6+
public class Solution {
7+
public int singleNonDuplicate(int[] nums) {
8+
if (nums.length == 0)
9+
{
10+
return 0;
11+
}
12+
int res = nums[0];
13+
for (int i = 1; i < nums.length; i++)
14+
{
15+
res ^= nums[i];
16+
}
17+
return res;
18+
}
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
 /**
2+
*
3+
*
4+
*
5+
*/
6+
public class Solution {
7+
public String reverseWords(String s)
8+
{
9+
if (s == null || s.isEmpty())
10+
{
11+
return "";
12+
}
13+
String[] strs = s.split(" ");
14+
StringBuilder sb = new StringBuilder(s.length());
15+
for (int i = 0; i < strs.length; i++)
16+
{
17+
sb.append(reverseWord(strs[i])).append(" ");
18+
}
19+
return sb.toString().trim();
20+
}
21+
22+
private String reverseWord(String s)
23+
{
24+
StringBuilder sb = new StringBuilder(s.length());
25+
return sb.append(s).reverse().toString();
26+
}
27+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy