
- 系列文章目录
- 一
- 1.反转字符串
- 2.最大公约数
C
char* solve(char* str ) {
// write code here
char *f, *r;
char temp;
f = r = str;
if(*str == ' ')
return str;
while(*r != '')
r++;
r--;
while(r - f > 0){
temp = *r;
*r = *f;
*f = temp;
f++;
r--;
}
return str;
}
java
import java.util.*;
public class Solution {
public String solve (String str) {
// write code here
int j = 0;
char[] s2 = new char[str.length()];
for(int i = 0; i < str.length(); i++){
s2[j++] = str.charAt(str.length()-1-i);
}
return new String(s2);
}
}
2.最大公约数
public class Solution {
public int gcd (int a, int b) {
// write code here
int t;
if(a < b)
{
t = a;
a = b;
b = t;
}
while(b > 0){
t = a % b;
a = b;
b = t;
}
return a;
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)