Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdc964fd

Browse files
committed
math
1 parentfc1528b commitdc964fd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

‎dp/IsMatch.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public static boolean isMatch(String s, String p) {
114114
}
115115
}
116116

117+
// 跳过末尾的所有的*.
118+
while (indexP <lenP &&p.charAt(indexP) =='*') {
119+
indexP++;
120+
}
121+
117122
if (indexS ==lenS &&indexP ==lenP) {
118123
returntrue;
119124
}

‎string/Multiply.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packageAlgorithms.string;
2+
3+
publicclassMultiply {
4+
publicstaticvoidmain(String[]strs) {
5+
multiply("9","9");
6+
}
7+
8+
publicstaticStringmultiply(Stringnum1,Stringnum2) {
9+
if (num1 ==null ||num2 ==null) {
10+
returnnull;
11+
}
12+
13+
intlen1 =num1.length();
14+
intlen2 =num2.length();
15+
16+
int[]product =newint[len1 +len2];
17+
18+
// 计算相应位置的product.
19+
for (inti =0;i <len1;i++) {
20+
for (intj =0;j <len2;j++) {
21+
product[i +j] = (num1.charAt(len1 -1 -i) -'0') * (num2.charAt(len2 -1 -j) -'0');
22+
}
23+
}
24+
25+
StringBuilderret =newStringBuilder();
26+
27+
intcarry =0;
28+
for (inti =0;i <len1 +len2;i++) {
29+
product[i] =product[i] +carry;
30+
intdigit =product[i] %10;
31+
carry =digit /10;
32+
ret.insert(0,digit);
33+
}
34+
35+
while (ret.length() >1 &&ret.charAt(0) =='0') {
36+
ret.deleteCharAt(0);
37+
}
38+
39+
returnret.toString();
40+
}
41+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp