Test 2 Finished

This commit is contained in:
Kagura 2024-03-19 14:27:36 +08:00
parent 4e4b394aad
commit 17b6c6e9a4
5 changed files with 54 additions and 17 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View file

@ -8,7 +8,7 @@
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
</content> </content>
<orderEntry type="jdk" jdkName="23" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component> </component>

View file

@ -2,6 +2,6 @@
fun main() { fun main() {
val t = Test3()
t.test()
} }

View file

@ -4,25 +4,52 @@ class Test2 {
var next: ListNode? = null var next: ListNode? = null
} }
fun addTwoNumbers(l1: ListNode?, l2: ListNode?): ListNode? { fun getVal(l: ListNode?): Int {
val cf = false return l?.`val` ?: 0
val result = ListNode(1) }
if (l1 != null) {
if (l2!=null){
} 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
} }
return null
if (cf == 1){
current?.next = ListNode(1)
}
return result.next
} }
fun test(){ fun test(){
val li1 = ListNode(2) val li1 = ListNode(9)
li1.next = ListNode(4) li1.next = ListNode(9)
li1.next!!.next = ListNode(3) 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
View file

@ -0,0 +1,10 @@
class Test3 {
fun lengthOfLongestSubstring(s: String): Int {
}
fun test(){
}
}