commit push
This commit is contained in:
parent
0f344a1655
commit
f0852e34a1
Binary file not shown.
|
|
@ -0,0 +1,82 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.cqu.ge</groupId>
|
||||||
|
<artifactId>GE_migate</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.cqu</groupId>
|
||||||
|
<artifactId>ge</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--utgard -->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.openscada.external</groupId>-->
|
||||||
|
<!-- <artifactId>org.openscada.external.jcifs</artifactId>-->
|
||||||
|
<!-- <version>1.2.25</version>-->
|
||||||
|
<!-- <exclusions>-->
|
||||||
|
<!-- <exclusion>-->
|
||||||
|
<!-- <groupId>org.bouncycastle</groupId>-->
|
||||||
|
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
|
||||||
|
<!-- </exclusion>-->
|
||||||
|
<!-- </exclusions>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!--<!– <dependency>–>-->
|
||||||
|
<!--<!– <groupId>org.openscada.jinterop</groupId>–>-->
|
||||||
|
<!--<!– <artifactId>org.openscada.jinterop.core</artifactId>–>-->
|
||||||
|
<!--<!– <version>2.1.8</version>–>-->
|
||||||
|
<!--<!– </dependency>–>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.openscada.jinterop</groupId>-->
|
||||||
|
<!-- <artifactId>org.openscada.jinterop.deps</artifactId>-->
|
||||||
|
<!-- <version>1.5.0</version>-->
|
||||||
|
<!-- <exclusions>-->
|
||||||
|
<!-- <exclusion>-->
|
||||||
|
<!-- <groupId>org.bouncycastle</groupId>-->
|
||||||
|
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
|
||||||
|
<!-- </exclusion>-->
|
||||||
|
<!-- </exclusions>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.openscada.utgard</groupId>-->
|
||||||
|
<!-- <artifactId>org.openscada.opc.dcom</artifactId>-->
|
||||||
|
<!-- <version>1.5.0</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.openscada.utgard</groupId>-->
|
||||||
|
<!-- <artifactId>org.openscada.opc.lib</artifactId>-->
|
||||||
|
<!-- <version>1.5.0</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.bouncycastle</groupId>-->
|
||||||
|
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
|
||||||
|
<!-- <version>1.61</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>ch.qos.logback</groupId>-->
|
||||||
|
<!-- <artifactId>logback-core</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>ch.qos.logback</groupId>-->
|
||||||
|
<!-- <artifactId>logback-classic</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,157 @@
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class OracleODBC {
|
||||||
|
private static Connection conn;
|
||||||
|
private static PreparedStatement ps;
|
||||||
|
private static ResultSet rs;
|
||||||
|
private static String odbc_driver;
|
||||||
|
private static String odbc_url;
|
||||||
|
private static String username;
|
||||||
|
private static String password;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 测试
|
||||||
|
String sql = "select * from emp";
|
||||||
|
System.out.println("ODBC************");
|
||||||
|
ResultSet rst = OracleODBC.executeQuery(sql, null);
|
||||||
|
try {
|
||||||
|
while(rst.next()){
|
||||||
|
System.out.println(rst.getString("ename"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
OracleODBC.close(OracleODBC.getConn(),OracleODBC.getPs(),rst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static{
|
||||||
|
try {
|
||||||
|
Map<String,String> map = get();
|
||||||
|
odbc_driver = map.get("odbc_driver");
|
||||||
|
odbc_url = map.get("odbc_url");
|
||||||
|
username = map.get("username");
|
||||||
|
password = map.get("password");
|
||||||
|
|
||||||
|
Class.forName(odbc_driver);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化变量
|
||||||
|
public static Map get(){
|
||||||
|
Properties pp = new Properties();
|
||||||
|
FileInputStream fis = null;
|
||||||
|
Map<String,String> map = new HashMap<String, String>();
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream("dbinfor.properties");//dbinfor.properties在工程路径下面
|
||||||
|
pp.load(fis);
|
||||||
|
odbc_driver = pp.getProperty("odbc_driver");
|
||||||
|
odbc_url = pp.getProperty("odbc_url");
|
||||||
|
username = pp.getProperty("username");
|
||||||
|
password = pp.getProperty("password");
|
||||||
|
map.put("odbc_driver", odbc_driver);
|
||||||
|
map.put("odbc_url", odbc_url);
|
||||||
|
map.put("username", username);
|
||||||
|
map.put("password", password);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
//增删改方法
|
||||||
|
public static void executeUpdate(String sql,String []parameters){
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(odbc_url, username, password);
|
||||||
|
ps = conn.prepareStatement(sql);
|
||||||
|
if(parameters!=null){
|
||||||
|
for(int i=0;i<parameters.length;i++){
|
||||||
|
ps.setString(i+1, parameters[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ps.executeUpdate();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
|
}finally{
|
||||||
|
OracleODBC.close(conn, ps, rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询方法
|
||||||
|
public static ResultSet executeQuery(String sql,String []parameters){
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection(odbc_url, username, password);
|
||||||
|
ps = conn.prepareStatement(sql);
|
||||||
|
if(parameters !=null){
|
||||||
|
for(int i=0;i<parameters.length;i++){
|
||||||
|
ps.setString(i+1, parameters[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//执行查询
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
|
}finally{
|
||||||
|
//关闭资源
|
||||||
|
//SQLHelper.close(conn, ps, rs);
|
||||||
|
}
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
//关闭资源
|
||||||
|
public static void close(Connection conn,Statement stmt,ResultSet rs){
|
||||||
|
if(rs!=null){
|
||||||
|
try {
|
||||||
|
rs.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
rs = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stmt!=null){
|
||||||
|
try {
|
||||||
|
stmt.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
stmt = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(conn!=null){
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
conn=null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Connection getConn() {
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PreparedStatement getPs() {
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.cqu.ge;
|
||||||
|
|
||||||
|
import com.sun.security.ntlm.Server;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class TestData {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
|
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
|
||||||
|
|
||||||
|
String ds="jdbc:odbc:Provider=IhOLEDB.iHistorian.1;Persist Security Info=True;Mode=Read;Data Source=192.168.9.8";
|
||||||
|
// String ds="Provider=IhOLEDB.iHistorian.1;Persist Security Info=True;Mode=Read;Data Source=192.168.9.8";
|
||||||
|
|
||||||
|
String user="administrator";
|
||||||
|
String password="TES@ihistorian2018";
|
||||||
|
|
||||||
|
Class.forName(driver);
|
||||||
|
|
||||||
|
Connection connection = DriverManager.getConnection(ds, user, password);
|
||||||
|
|
||||||
|
|
||||||
|
//3.定义sql
|
||||||
|
String sql = "select * from ihTags where tagname= [HN.DF.DF11.DF11_TC1].AIO.AN_Air_Supply_Pressure ";
|
||||||
|
|
||||||
|
//4.获取执行sql对象statement
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
|
||||||
|
//5.执行sql
|
||||||
|
int count = statement.executeUpdate(sql); //返回受影响的行数
|
||||||
|
|
||||||
|
//6.处理结果
|
||||||
|
System.out.println(count);
|
||||||
|
|
||||||
|
//7.释放资源
|
||||||
|
statement.close();
|
||||||
|
connection.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.cqu.ge;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class test1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
Class.forName("org.objectweb.rmijdbc.Driver").newInstance();
|
||||||
|
String strurl = "jdbc:rmi://111.11.1.1/jdbc:odbc:sundy4";
|
||||||
|
java.sql.Connection c = DriverManager.getConnection(strurl, "", "199302");
|
||||||
|
java.sql.Statement st = c.createStatement();
|
||||||
|
java.sql.ResultSet rs = st.executeQuery("select * from Users");
|
||||||
|
java.sql.ResultSetMetaData md = rs.getMetaData();
|
||||||
|
|
||||||
|
while(rs.next()) {
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
for(int i=1; i<= md.getColumnCount(); i++) {
|
||||||
|
|
||||||
|
System.out.print(rs.getString(i) + " | ");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
package com.markilue.leecode.interview.meituan;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: Leecode
|
||||||
|
* @BelongsPackage: com.markilue.leecode.interview.meituan
|
||||||
|
* @Author: marklue
|
||||||
|
* @CreateTime: 2023/3/25 19:08
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class Question2 {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
int value = 7;
|
||||||
|
int[] nums = {3, 1, 2, 7, 10, 2, 4};
|
||||||
|
sovle1(nums);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sovle(int[] nums) {
|
||||||
|
int n = nums.length;
|
||||||
|
int[] dp = new int[n + 1];
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
dp[i] = dp[i - 1];
|
||||||
|
if (i >= 2) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[i - 2] + nums[i - 1]);
|
||||||
|
}
|
||||||
|
if (i >= 3) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[i - 3] + nums[i - 1]);
|
||||||
|
}
|
||||||
|
if (i >= 4 && i != 5) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[i - 4] + nums[i - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(dp[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sovle1(int[] nums) {
|
||||||
|
int n = nums.length;
|
||||||
|
int[] dp = new int[n];//[不选,选]
|
||||||
|
dp[0]=nums[0];
|
||||||
|
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
if (i >= 3) {
|
||||||
|
dp[i] = Math.max(dp[i - 3] + nums[i],dp[i - 1]);
|
||||||
|
} else {
|
||||||
|
dp[i]=Math.max(dp[i-1],nums[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(dp[n-1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int n = sc.nextInt();
|
||||||
|
int[] a = new int[n];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
a[i] = sc.nextInt();
|
||||||
|
}
|
||||||
|
sc.close();
|
||||||
|
|
||||||
|
int[] dp = new int[n + 1];
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
dp[i] = dp[i - 1];
|
||||||
|
if (i >= 2) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[i - 2] + a[i - 1]);
|
||||||
|
}
|
||||||
|
if (i >= 3) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[i - 3] + a[i - 1]);
|
||||||
|
}
|
||||||
|
if (i >= 4 && i != 5) {
|
||||||
|
dp[i] = Math.max(dp[i], dp[i - 4] + a[i - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(dp[n]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.markilue.leecode.interview.meituan;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: Leecode
|
||||||
|
* @BelongsPackage: com.markilue.leecode.interview.meituan
|
||||||
|
* @Author: marklue
|
||||||
|
* @CreateTime: 2023/3/25 19:18
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class Question3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int m = sc.nextInt();
|
||||||
|
int n = sc.nextInt();
|
||||||
|
int[] weight = new int[m];
|
||||||
|
int[] bag = new int[n];
|
||||||
|
int max = 0;
|
||||||
|
for (int i = 0; i < weight.length; i++) {
|
||||||
|
weight[i] = sc.nextInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
bag[i] = sc.nextInt();
|
||||||
|
max = Math.max(max, bag[i]);
|
||||||
|
}
|
||||||
|
int[] dp = new Question3().sovle(weight, max);
|
||||||
|
for (int i : bag) {
|
||||||
|
System.out.print(dp[i] + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
int[] nums = {5,2,1,4,2};
|
||||||
|
sovle(nums, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] sovle(int[] weight, int bag) {
|
||||||
|
int[][] dp = new int[weight.length][bag + 1];
|
||||||
|
|
||||||
|
for (int i = 0; i < dp[0].length; i++) {
|
||||||
|
if (i >= weight[0] * weight[0]) dp[0][i] = 1;
|
||||||
|
}
|
||||||
|
for (int i = 1; i < dp.length; i++) {
|
||||||
|
for (int j = 1; j < dp[0].length; j++) {
|
||||||
|
int weight1 = weight[i] * weight[i];
|
||||||
|
if (weight1 > j) dp[i][j]=dp[i-1][j];
|
||||||
|
else dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weight1] + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for (int i = 0; i < dp.length; i++) {
|
||||||
|
// System.out.println(Arrays.toString(dp[i]));
|
||||||
|
// }
|
||||||
|
return dp[dp.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.markilue.leecode.interview.meituan;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: Leecode
|
||||||
|
* @BelongsPackage: com.markilue.leecode.interview.meituan
|
||||||
|
* @Author: marklue
|
||||||
|
* @CreateTime: 2023/3/25 20:24
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class Question4 {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int n = sc.nextInt();
|
||||||
|
int k = sc.nextInt();
|
||||||
|
int[] a = new int[n + 1];
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
a[i] = sc.nextInt();
|
||||||
|
}
|
||||||
|
int[][][] dp = new int[n + 1][k + 1][2];
|
||||||
|
// 初始化
|
||||||
|
for (int j = 0; j <= k; j++) {
|
||||||
|
dp[1][j][0] = 0;
|
||||||
|
dp[1][j][1] = a[1];
|
||||||
|
}
|
||||||
|
// 状态转移
|
||||||
|
for (int i = 2; i <= n; i++) {
|
||||||
|
for (int j = 0; j <= k; j++) {
|
||||||
|
dp[i][j][0] = Math.max(dp[i - 1][j][0], dp[i - 1][j][1]);
|
||||||
|
if (j > 0) {
|
||||||
|
dp[i][j][1] = Math.max(dp[i - 1][j - 1][1] + a[i], dp[i - 1][j][0] + a[i]);
|
||||||
|
} else {
|
||||||
|
dp[i][j][1] = dp[i - 1][j][0] + a[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 取最大值
|
||||||
|
int ans = 0;
|
||||||
|
for (int j = 0; j <= k; j++) {
|
||||||
|
ans = Math.max(ans, Math.max(dp[n][j][0], dp[n][j][1]));
|
||||||
|
}
|
||||||
|
System.out.println(ans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.markilue.leecode.listnode.selftry;
|
||||||
|
|
||||||
|
import com.markilue.leecode.listnode.ListNode;
|
||||||
|
import com.markilue.leecode.listnode.ListNodeUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DeleteDuplicates {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
ListNode root = ListNodeUtils.build(new int[]{1, 1, 2, 2});
|
||||||
|
ListNodeUtils.print(deleteDuplicates(root));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ListNode deleteDuplicates(ListNode head) {
|
||||||
|
|
||||||
|
ListNode fake = new ListNode();
|
||||||
|
fake.next = head;
|
||||||
|
ListNode temp = head;
|
||||||
|
while (temp != null) {
|
||||||
|
if (temp.next != null && temp.val == temp.next.val) {
|
||||||
|
ListNode temp1 = temp.next;
|
||||||
|
while (temp1.next != null && temp1.val == temp1.next.val) {
|
||||||
|
temp1 = temp1.next;
|
||||||
|
}
|
||||||
|
temp.next = temp1.next;
|
||||||
|
}
|
||||||
|
temp = temp.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fake.next;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListNode deleteDuplicates1(ListNode head) {
|
||||||
|
if (head == null) {
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
ListNode cur = head;
|
||||||
|
while (cur.next != null) {
|
||||||
|
if (cur.val == cur.next.val) {
|
||||||
|
cur.next = cur.next.next;
|
||||||
|
} else {
|
||||||
|
cur = cur.next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.markilue.leecode.listnode.selftry;
|
||||||
|
|
||||||
|
|
||||||
|
import com.markilue.leecode.listnode.ListNode;
|
||||||
|
import com.markilue.leecode.listnode.ListNodeUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: Leecode
|
||||||
|
* @BelongsPackage: com.markilue.leecode.listnode.selftry
|
||||||
|
* @Author: marklue
|
||||||
|
* @CreateTime: 2023/3/25 18:50
|
||||||
|
* @Description: TODO 美团笔试 链表去重升级:把重复的也去掉
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class DeleteDuplicatesII {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
ListNode root = ListNodeUtils.build(new int[]{1, 1, 2,2,2});
|
||||||
|
ListNodeUtils.print(deleteDuplicates(root));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ListNode deleteDuplicates(ListNode head) {
|
||||||
|
|
||||||
|
if (head == null) {
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
ListNode fake = new ListNode();
|
||||||
|
fake.next = head;
|
||||||
|
ListNode temp = fake;
|
||||||
|
while (temp.next != null) {
|
||||||
|
if (temp.next.next != null && temp.next.val == temp.next.next.val) {
|
||||||
|
ListNode temp1 = temp.next;
|
||||||
|
while (temp1.next != null && temp1.val == temp1.next.val) {
|
||||||
|
temp1 = temp1.next;
|
||||||
|
}
|
||||||
|
temp.next = temp1.next;
|
||||||
|
}else {
|
||||||
|
temp = temp.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return fake.next;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import pyodbc
|
||||||
|
|
||||||
|
# 定义连接字符串
|
||||||
|
conn_str = (
|
||||||
|
r"DRIVER=IhOLEDB.iHistorian.1;"
|
||||||
|
r"Persist Security Info=True;"
|
||||||
|
r"Mode=Read;"
|
||||||
|
r"server=192.168.9.8;"
|
||||||
|
r"uid=administrator;"
|
||||||
|
r"pwd=TES@ihistorian2018;"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 使用pyodbc连接数据库
|
||||||
|
cnxn = pyodbc.connect(conn_str)
|
||||||
|
|
||||||
|
# 执行SQL查询
|
||||||
|
cursor = cnxn.cursor()
|
||||||
|
cursor.execute("select * from ihTags where tagname= [HN.DF.DF11.DF11_TC1].AIO.AN_Air_Supply_Pressure")
|
||||||
|
|
||||||
|
# 处理结果集
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
# 关闭连接
|
||||||
|
cnxn.close()
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.makrilue.interview</groupId>
|
||||||
|
<artifactId>Tecent</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.markilue.interview;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.notification.RunListener;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Question3 {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
String s = "nowcoder";
|
||||||
|
String[] dic = {"now", "coder", "no", "wcoder"};
|
||||||
|
System.out.println(Arrays.toString(wordDiv(s, dic)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
|
||||||
|
*
|
||||||
|
* @param s string字符串
|
||||||
|
* @param dic string字符串一维数组
|
||||||
|
* @return string字符串一维数组
|
||||||
|
*/
|
||||||
|
public String[] wordDiv(String s, String[] dic) {
|
||||||
|
// write code here
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
if (s == null || s.length() == 0 || dic.length == 0) {
|
||||||
|
return result.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
List<String> wordDic = Arrays.asList(dic);
|
||||||
|
HashSet<String> set = new HashSet<>(wordDic);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
backtracking(s, set, 0, sb, result);
|
||||||
|
return result.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void backtracking(String s, HashSet<String> set, int start, StringBuilder sb, List<String> result) {
|
||||||
|
if (start == s.length()) {
|
||||||
|
result.add(sb.toString().trim());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = start; i < s.length(); i++) {
|
||||||
|
String word = s.substring(start, i + 1);
|
||||||
|
if (set.contains(word)) {
|
||||||
|
sb.append(word).append(" ");
|
||||||
|
backtracking(s, set, i + 1, sb, result);
|
||||||
|
sb.delete(sb.length() - word.length() - 1, sb.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.markilue.interview;
|
||||||
|
|
||||||
|
public class Question4 {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue