手撕算法
字符串 医生患者消息 计算 对话来回次数 ab算一次,abb一次 aba一次 aabb一次
abab两次 abba两次 abbba两次
public int sumTalk(String s){
char[] array = s.toCharArray();
int count = 0;
int i = 0;
while (i < array.length - 1){
if(array[i] == 'a' ){
int j = i + 1;
while (j < array.length && array[j] != 'b'){
++j;
}
if(j >= array.length){
break;
}
++count;
i = j + 1;
}else if(array[i] == 'b'){
int j = i + 1;
while (j < array.length && array[j] != 'a'){
++j;
}
if(j >= array.length){
break;
}
++count;
i = j + 1;
}
}
return count;
}
项目相关
- redis
- RabbitMQ
- 乐观锁
- Token
Java
- final关键字
- ConcurrentHashmap
手写SQL
表有药房药材room
药房room_id,药材item_id,价格price,每个药房药价大于1数量 药房room_id 数量sum
SELECT
room_id,
COUNT(item_id) AS sum
FROM
room
WHERE
price > 1
GROUP BY
room_id;
Comments NOTHING