Published on

ARTS 第31周

Authors

Algorithm

package org.nocoder.leetcode.solution;

/**
 * 905. Sort Array By Parity
 * Given an array A of non-negative integers, return an array consisting of all the even elements of A,
 * followed by all the odd elements of A.
 * <p>
 * You may return any answer array that satisfies this condition.
 * <p>
 * Example 1:
 * <p>
 * Input: [3,1,2,4]
 * Output: [2,4,3,1]
 * The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted.
 * <p>
 * <p>
 * Note:
 * <p>
 * 1 <= A.length <= 5000
 * 0 <= A[i] <= 5000
 *
 * @author jason
 * @date 2019/2/25.
 */
public class SortArrayByParity {
    public static int[] sortArrayByParity(int[] arr) {
        int[] sortedArray = new int[arr.length];
        int idx = 0;

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                sortedArray[idx++] = arr[i];
            }
        }

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 1) {
                sortedArray[idx++] = arr[i];
            }
        }

        return sortedArray;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{3, 1, 2, 4};
        sortArrayByParity(arr);
    }
}

Review

Quick Tips for Fast Code on the JVM

Tip

IDEA lombok @Slf4j 简化日志开发

lombok 为我们提供了很多便捷的注解来简化开发,使用 @Slf4j 后可以直接使用 log 变量来记录日志。 在IDEA 下使用这个注解,需要本地环境的支持,安装 lombok 插件。 idea_lombok_plugin

配置完成后,需要重新启动 idea

引入 lombok jar 文件,maven 项目中,在 pom.xml 中添加以下依赖

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.18</version>
</dependency>
package org.nocoder.demo;

import lombok.extern.slf4j.Slf4j;

/**
 * Test Slf4j annotation
 * @author jason
 * @date 2019/2/18.
 */
@Slf4j
public class TestSlf4j {
    public static void main(String[] args) {
        log.debug("hello world!");
        String user = "Jason";
        log.info("hello, {}", user);
    }
}

输出

15:21:28.510 [main] DEBUG org.nocoder.demo.TestSlf4j - hello world!
15:29:29.312 [main] INFO org.nocoder.demo.TestSlf4j - hello, Jason

Share

解决 Windows 7 IE11 HTML 页面打开空白问题

  • 问题原因:浏览器默认按照<META content="IE=7" http-equiv="X-UA-Compatible">来渲染页面

    • 版本:11.0.9600.19080
    • 更新版本:11.0.70(KB4339093)
    • 产品ID:00150-20000-00003-AA459
  • 解决办法:index.html 添加<META content="IE=Edge" http-equiv="X-UA-Compatible"> 强制浏览器使用最新版本的内核来渲染页面