我越来越懂linklist了(应该吧?),可喜可贺
题号:21 标题:Merge Two Sorted Lists 难度:Easy
Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
ListNode result = new ListNode();
ListNode cur = new ListNode();
ListNode temp = new ListNode();
int start = 0;
if(l1 == null && l2==null){
return l1;
}
while(l1 != null || l2!= null){
//System.out.println("v1:" + l1.val + " v2:" + l2.val);
if(l1 == null){
if(start == 0){
result = l2;
cur = l2;
temp = l2;
System.out.println("1:" + cur.val);
l2 = l2.next;
start++;
}else{
temp.next = l2;
System.out.println("2:" + l2.val);
cur = temp.next;
temp = l2;
l2 = l2.next;
}
}else if(l2 == null){
if(start == 0){
result = l1;
cur = l1;
temp = l1;
System.out.println("3:" + cur.val);
l1 = l1.next;
start++;
}else{
temp.next = l1;
cur = temp.next;
temp = cur;
System.out.println("4:" + cur.val);
l1 = l1.next;
}
}else{
if(l1.val <= l2.val && start == 0){
result = l1;
cur = l1;
temp = l1;
System.out.println("5:" + cur.val);
l1 = l1.next;
start++;
}else if(l2.val < l1.val && start == 0){
result = l2;
cur = l2;
temp = l2;
System.out.println("7:" + cur.val);
l2 = l2.next;
start++;
}else if(l1.val <= l2.val ){
temp.next = l1;
cur = temp.next;
temp = cur;
System.out.println("6:" + cur.val);
l1 = l1.next;
}else{
temp.next = l2;
System.out.println("8:" + cur.val);
cur = temp.next;
temp = cur;
l2 = l2.next;
}
}
}
return result;
}
}
题号:205 标题:Isomorphic Strings 难度:Easy
Given two strings s and t, determine if they are isomorphic.
Two strings s and t are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
Example 1:
Input: s = "egg", t = "add"
Output: true
Example 2:
Input: s = "foo", t = "bar"
Output: false
Example 3:
Input: s = "paper", t = "title"
Output: true
Constraints:
• 1 <= s.length <= 5 * 104
• t.length == s.length
• s and t consist of any valid ascii character.
bool isIsomorphic(char * s, char * t){
int len=strlen(s),i,j;
//printf("%d,%d",lens,lent);
int temp[128]={0};
for(i=0;i<len;i++){
if(temp[s[i]]==0){
temp[s[i]] = t[i];
}else if(temp[s[i]] != t[i]){
return false;
}
}
int temp2[128]={0};
for(i=0;i<len;i++){
if(temp2[t[i]]==0){
temp2[t[i]] = s[i];
}else if(temp2[t[i]] != s[i]){
return false;
}
}
return true;
}
DAY18心得
我有进步的感觉,开心
>>: [Day 28] 建立 migration 时使用的套件,来谈谈 Flyway
问题回答 slot(插槽)的概念是把外层的内容塞进子元件的指定位置里。跟插槽的字面意思一样,前提是:...
reference: medium - Filtering Image content with ...
-波特的价值链(Porter’s Value Chain) 业务就是提供产品和服务以创造价值并实现...
再写登入的验证及功能 今天我们要来做登入的判断跟动作, 我们在HomeController.php引...
游戏专题进行了半个月,耗费最大的心力是在处理碰撞的逻辑问题,为1 Pixcel的逻辑误差斤斤计较,不...