扫一扫
关注公众号
ARTS的初衷
Algorithm: 主要是为了编程训练和学习。
Review:主要是为了学习英文
Tip:主要是为了总结和归纳在是常工作中所遇到的知识点。学习至少一个技术技巧。在工作中遇到的问题,踩过的坑,学习的点滴知识。
Share:主要是为了建立影响力,能够输出价值观。分享一篇有观点和思考的技术文章
https://www.zhihu.com/question/301150832
Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
Example:
Input:
[4,3,2,7,8,2,3,1]
Output:
[2,3]
class Solution {
public List<Integer> findDuplicates(int[] nums) {
// 正负位置标记法
List<Integer> res = new ArrayList();
for(int n:nums) {
int tmp = Math.abs(n);
if(nums[tmp-1]<-1) {
res.add(tmp);
} else {
nums[tmp-1]*=-1;
}
}
return res;
}
}
How to Create a Scrollable, Updatable ResultSet Object in JDBC
通过设置ResultSet参数,可以让我们以游标的方式遍历和更新数据,比如方法first()、previous()、 next()、last()、updateRow()
查询
PreparedStatement pstmt =
connection.prepareStatement(SQL,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);){
rs = pstmt.executeQuery();
更新
PreparedStatement pstmt =
connection.prepareStatement(SQL,
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);){
pstmt.setLong(1,emp_no);
rs = pstmt.executeQuery();
while(rs.next()){
show(rs);
rs.updateString("first_name", "Subham");
rs.updateRow();
}
resultSetType 的可选值有:
Java和Mysql数据类型转换时,要注意tinyInt类型,如果存储长度为1,会转换成java.lang.Boolean,可以在JDBC的URL上增加tinyInt1isBit=false参数,禁止自动转换