Test 2 Finished
This commit is contained in:
parent
4e4b394aad
commit
17b6c6e9a4
5 changed files with 54 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="23" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -8,7 +8,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="23" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
|
||||
fun main() {
|
||||
|
||||
|
||||
val t = Test3()
|
||||
t.test()
|
||||
}
|
51
src/Test2.kt
51
src/Test2.kt
|
@ -4,25 +4,52 @@ class Test2 {
|
|||
var next: ListNode? = null
|
||||
}
|
||||
|
||||
fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {
|
||||
val cf = false
|
||||
val result = ListNode(1)
|
||||
if (l1 != null) {
|
||||
if (l2!=null){
|
||||
fun getVal(l: ListNode?): Int {
|
||||
return l?.`val` ?: 0
|
||||
}
|
||||
|
||||
fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? {
|
||||
var cf = 0
|
||||
var l1 = l1
|
||||
var l2 = l2
|
||||
val result: ListNode = ListNode(0)
|
||||
var current: ListNode? = result
|
||||
|
||||
|
||||
while (l1!=null||l2!=null){
|
||||
val t = getVal(l1) + getVal(l2) + cf
|
||||
cf = t/10
|
||||
current?.next = ListNode(t%10)
|
||||
current = current?.next
|
||||
l1 = l1?.next
|
||||
l2 = l2?.next
|
||||
}
|
||||
|
||||
if (cf == 1){
|
||||
current?.next = ListNode(1)
|
||||
}
|
||||
return null
|
||||
|
||||
return result.next
|
||||
}
|
||||
|
||||
fun test(){
|
||||
val li1 = ListNode(2)
|
||||
li1.next = ListNode(4)
|
||||
li1.next!!.next = ListNode(3)
|
||||
val li1 = ListNode(9)
|
||||
li1.next = ListNode(9)
|
||||
li1.next!!.next = ListNode(9)
|
||||
li1.next!!.next!!.next = ListNode(9)
|
||||
|
||||
|
||||
val li2 = ListNode(9)
|
||||
li2.next = ListNode(9)
|
||||
li2.next!!.next = ListNode(9)
|
||||
|
||||
var result = addTwoNumbers(li1,li2)
|
||||
while (result!=null){
|
||||
print(result.`val`)
|
||||
print(",")
|
||||
result=result.next
|
||||
}
|
||||
|
||||
val li2 = ListNode(5)
|
||||
li2.next = ListNode(6)
|
||||
li2.next!!.next = ListNode(4)
|
||||
|
||||
}
|
||||
}
|
10
src/Test3.kt
Normal file
10
src/Test3.kt
Normal file
|
@ -0,0 +1,10 @@
|
|||
class Test3 {
|
||||
|
||||
fun lengthOfLongestSubstring(s: String): Int {
|
||||
|
||||
}
|
||||
|
||||
fun test(){
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue