问题取自编程访谈要素:
给定具有布尔值键的n个对象的数组A,对数组重新排序,以便首先出现具有错误键的对象.具有键true的对象的相对排序不应更改.使用O(1)额外空间和O(n)时间.
我做了以下操作,它保留了对象为true的对象的相对排序,并使用了O(1)额外空间,但我相信它的时间复杂度为O(n*n!).
public static void rearrangeVariant4(Boolean[] a) {
int lastFalseIdx = 0;
for (int i = 0; i < a.length; i++) {
if (a[i].equals(false)) {
int falseIdx = i;
while (falseIdx > lastFalseIdx) {
swap(a, falseIdx, falseIdx-1);
falseIdx--;
}
lastFalseIdx++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何在O(n)时间内解决它?
我使用官方支持的mysql映像创建了一个mysql容器.我运行图像挂载包含sql转储的文件夹,然后我在容器中创建了一个新数据库并导入了.sql转储:
sudo docker run --name mysql-psat1 -v /opt/Projets/P1/sqldumps:/mnt -e MYSQL_ROOT_PASSWORD=secret -d mysql:latest
sudo docker exec -it mysql-psat1 bash
> mysql -uroot -psecret -e 'create database liferay_psat1;'
> mysql -uroot -psecret liferay_psat1 < /mnt/liferay_sql_dump.sql
Run Code Online (Sandbox Code Playgroud)
然后我列出了正在运行的容器来获取该容器的id:
sudo docker ps -a
Run Code Online (Sandbox Code Playgroud)
然后,我将容器(使用导入的sql)作为新的容器映像提交
sudo docker commit -m "Imported liferay sql dump" <id-of-the-container> jihedamine/mysql-psat1:v1
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用该新映像启动容器,则mysql数据库不包含新创建的数据库liferay_psat1.
sudo docker run -ti jihedamine/mysql-psat1:v1 bash
> mysql -uroot -psecret
# show databases;
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢你的帮助!
使用eclipse 3.5,当我创建一个新的maven项目时,m2eclipse自动将J2SE1.4添加到库,将Compiler Compliance Level添加到1.4(项目属性> Java编译器).我的JRE系统库是1.6,我的默认编译器合规级别是1.6.我甚至没有安装1.4.我可以让m2eclipse使用我的默认设置并阻止它修改项目设置吗?
我创建了一个自定义的Hibernate事件监听器,扩展了org.hibernate.event.PreInsertEventListener.自定义侦听器覆盖onPreInsert方法,并在使用DAO将其保存到DB之前设置"Contact"实体的字段.
问题是,在侦听器为其赋值之前,该字段为null,并且在我的自定义侦听器之前自动触发默认的hibernate事件侦听器.当他们检查ddl时,他们会看到字段上的not-null约束,并在让我的自定义事件侦听器为字段赋值之前抛出空检查异常.(当使用spring AOP而不是hibernate自定义侦听器时会发生同样的问题:默认的hibernate侦听器在我的aspect方法之前执行)
因此,有可能在知道我使用spring会话工厂的情况下调整hibernate监听器的触发顺序吗?
谢谢
我想使用maven-jetty-plugin进行logback日志记录.显然,系统属性logback.configurationFile是在启动 maven-jetty-plugin并初始化slf4j后读取的,因此jetty不会读取./src/test/resources/logback.xml文件.因此,我将所有日志消息设置为调试级别并打印到控制台(默认的logback配置).用-Dlogback.configurationFile = ...启动maven解决了这个问题.但是,我更喜欢使用log4j和maven-jetty-plugin在pom中设置属性.有任何想法吗 ?
这是我的pom.xml:
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.4.v20111024</version>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<configuration>
<systemProperties>
<systemProperty>
<name>logback.configurationFile</name>
<value>./src/test/resources/logback.xml</value>
</systemProperty>
</systemProperties>
...
Run Code Online (Sandbox Code Playgroud)
这是logback.xml:
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud) val myBoolean = false & true
Run Code Online (Sandbox Code Playgroud)
在 Kotlin 中给出编译错误(意外标记(使用“;”分隔同一行上的表达式))
是否可以在类中声明ExceptionHandlers并在多个控制器中使用它们,因为在每个控制器中复制粘贴异常处理程序将是多余的.
- 声明异常处理程序:
@ExceptionHandler(IdentifiersNotMatchingException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
def @ResponseBody
String handleIdentifiersNotMatchingException(IdentifiersNotMatchingException e) {
logger.error("Identifiers Not Matching Error", e)
return "Identifiers Not Matching Error: " + e.message
}
@ExceptionHandler(ResourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
def @ResponseBody
String handleResourceNotFoundException(ResourceNotFoundException e) {
logger.error("Resource Not Found Error", e)
return "Resource Not Found Error: " + e.message
}
Run Code Online (Sandbox Code Playgroud)
-ContactController
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@RequestMapping(value = "contact/{publicId}", method = RequestMethod.DELETE)
def @ResponseBody
void deleteContact(@PathVariable("publicId") String publicId) throws ResourceNotFoundException, IdentifiersNotMatchingException {...}
Run Code Online (Sandbox Code Playgroud)
-LendingController
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@RequestMapping(value = "lending/{publicId}", …Run Code Online (Sandbox Code Playgroud)