我有以下问题要测试:
通过k步向右旋转n个元素的数组.
例如,当n = 7且k = 3时,阵列[1,2,3,4,5,6,7]旋转到[5,6,7,1,2,3,4].您知道解决此问题的方式有多少种?
我的中间阵列解决方案:
使用Space is O(n)和time O(n),我可以创建一个新数组,然后将元素复制到新数组.然后使用更改原始数组System.arraycopy().
public void rotate(int[] nums, int k) {
if(k > nums.length)
k=k%nums.length;
int[] result = new int[nums.length];
for(int i=0; i < k; i++){
result[i] = nums[nums.length-k+i];
}
int j=0;
for(int i=k; i<nums.length; i++){
result[i] = nums[j];
j++;
}
System.arraycopy( result, 0, nums, 0, nums.length );
}
Run Code Online (Sandbox Code Playgroud)
但是,有更好的方法可以通过空间中的气泡旋转(如气泡排序)来实现O(1吗?
我有一个在服务器X上运行的独立命令行java应用程序.我需要知道运行它的机器的唯一ID.如何获得此ID?也许像哈希一样.我不想保留那里有ID的文件.有没有办法获得这个不依赖于IP,硬件等的唯一ID?
我想连接多个数据库,如SQL和Oracle与不同的数据库.所以我已经有MSSQL hibernate.cfg.xml和Hibernateutil类用于会话工厂.现在我正在尝试连接oracle与不同的表.
请指教我可以使用相同的cgf.xml和util类也可以配置oracle数据库.
这是util类.
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
@SuppressWarnings("deprecation")
private static SessionFactory buildSessionFactory()
{
try
{
SessionFactory sessionFactory = new Configuration().configure("/DAO/hibernate.cfg.xml").buildSessionFactory();
return sessionFactory;
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Eclipse IDE将我的项目部署到tomcat7,我遇到了这个错误:
Uploading: http://localhost:8080/manager/html/deploy?path=%2Fexample
Uploaded: http://localhost:8080/manager/html/deploy?path=%2Fexample (13855 KB at 61573.5 KB/sec)
[ERROR] Tomcat return http status error: 403, Reason Phrase: Forbidden
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.259s
[INFO] Finished at: Sun Apr 20 09:44:18 GMT-03:00 2014
[INFO] Final Memory: 13M/223M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project example: Tomcat return http status error: 403, Reason Phrase: Forbidden: <html><head><title>Apache Tomcat/7.0.50 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} …Run Code Online (Sandbox Code Playgroud)