Algorithm
- 题目:
- 两数之和。给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
- 难度:简单
- 题解:
- 我的,暴力遍历,时间复杂的O(n2)
class Solution {
public int[] twoSum(int[] nums, int target) {
int[] arry = new int[2];
for(int i = 0; i < nums.length; ++i) {
for(int j = i+1; j < nums.length; ++j) {
if(target == nums[i] + nums[j]) {
arry[0] = i;
arry[1] = j;
}
}
}
return arry;
}
}
- 哈希映射,时间复杂度O(1)
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < nums.length; i++) {
if(map.containsKey(target - nums[i])) {
return new int[] {map.get(target-nums[i],i)};
}
map.put(nums[i], i);
}
return new int[0];
}
}
Review
- 文章:Mid Level Java Developer Questions — Job Interview
- 简介:本文介绍了11个中级Java面试问题
- 问题:在Java中有静态类吗,作者说没有静态类可以用以下方法代替。这个没太读懂
## Q-2: Is there anything like `static` class in Java?
## Answer
Java has no way of making a top-level class static but you can simulate a static class like this:
- Declare your class final — Prevents extension of the class since extending a static class makes no sense
- Make the constructor private — Prevents instantiation by client code as it makes no sense to instantiate a static class
- Make all the members and functions of the class static — Since the class cannot be instantiated no instance methods can be called or instance fields accessed
- Note that the compiler will not prevent you from declaring an instance (non-static) member. The issue will only show up if you attempt to call the instance member
- GPT的回答:
Java 中是存在静态类的概念的,但通常我们更常说的是静态成员和静态方法。静态类这个术语可能不太常见。 在 Java 中,类可以有静态成员(静态字段和静态方法),这些成员属于类本身,而不是类的实例。静态成员可以通过类名直接访问,而不需要创建类的实例。例如:
public class MyClass {
public static int staticField = 10;
public static void staticMethod() {
System.out.println("This is a static method.");
}
}
你可以通过以下方式访问静态成员:
int value = MyClass.staticField;
MyClass.staticMethod();
然而,Java 中的类本身不能被声明为静态。上述示例中的 MyClass 就是一个普通的类,但它拥有静态成员。所以,尽管我们不会说 "静态类",但我们可以通过创建只包含静态成员的类来实现类似于静态类的效果。
Technique/Tips
nginx -T命令- 作用:检查nginx配置文件 nginx.conf 的正确性
- 使用方法:
- nginx安装目录sbin下执行
./nginx -t - 显示
nginx.conf syntax is ok和nginx.conf test is successful则说明配置文件正确
- nginx安装目录sbin下执行
- 注意事项:
- 当普通用户安装使用nginx后,再使用root用户执行该命令会导致nginx安装目录权限改变
- 当nginx向安装目录的temp读写时,会因目录权限改变,导致依托nginx的应用无法访问。
Share
- StableDiffusion插件
- 插件安装与使用
- 扩展-可下载-本地化和已安装取消勾选-加载扩展列表,搜索需要安装的插件,点击安装
- 扩展-可安装,检查是否勾选下载的插件,应用更改并退出
- sd-webui-prompt-all-in-one插件介绍
- 作用:提示词翻译、管理
- 设置翻译 API,提示词下方-云朵按钮-填 APP ID和secret。
- 英文翻译成中文,可以设置提示词权重。
- 可以查看历史记录