Instantly share code, notes, and snippets.

# Desolve

• Sort options
Created Jan 8, 2020
0086 Partition List
View 0086 Partition List.java
 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode partition(ListNode head, int x) {
Created Jan 8, 2020
0086 Partition List
View 0086 Partition List.py
 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def partition(self, head: ListNode, x: int) -> ListNode: d1, d2 = ListNode(0), ListNode(0) ite = [d1, d2]
Created Jan 6, 2020
 class Solution: def checkIP(self, s: str, res: List[str], i: int, cnt: int, cur: str) -> None: if len(s) - i < 4 - cnt: return if cnt == 3: if len(s) - i <= 3: if s[i] != "0" and int(s[i:]) <= 255 or s[i:] == "0": cur += s[i:] res.append(cur) else: j = 1
Created Jan 6, 2020
 class Solution { public List restoreIpAddresses(String s) { List res = new LinkedList(); checkIP(s, res, 0, 0, ""); return res; } private void checkIP(String s, List res, int i, int cnt, String cur) { if (s.length() - i < 4 - cnt) return; if (cnt == 3) { if (s.length() - i <= 3) {
Created Jan 3, 2020
0082 Remove Duplicates from Sorted List II
View 0082 Remove Duplicates from Sorted List II.py
 # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplicates(self, head: ListNode) -> ListNode: if not head: return head dum = ListNode(0)
Created Jan 3, 2020
0082 Remove Duplicates from Sorted List II
View 0082 Remove Duplicates from Sorted List II.java
 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode deleteDuplicates(ListNode head) {
Created Dec 30, 2019
0383 Ransom Note
View 0383 Ransom Note.java
 class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] table = new int[26]; for (char c : magazine.toCharArray()) ++table[c - 'a']; for (char c : ransomNote.toCharArray()) if (--table[c - 'a'] < 0) return false; return true; } }
Created Dec 30, 2019
0383 Ransom Note
View 0383 Ransom Note.py
 class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: if len(ransomNote) > len(magazine): return False dic = {} for ch in magazine: if ch in dic: dic[ch] += 1 else:
Created Dec 28, 2019
0392 Is Subsequence
View 0392 Is Subsequence.java
 class Solution { public boolean isSubsequence(String s, String t) { if (s.length() > t.length()) return false; int pre = 0; for (int i = 0; i < s.length(); ++i, ++pre) { char si = s.charAt(i); pre = t.indexOf(si, pre); if (pre == -1) return false; } return true;
Created Dec 28, 2019
0392 Is Subsequence
View 0392 Is Subsequence.py
 class Solution: def isSubsequence(self, s: str, t: str) -> bool: if len(s) > len(t): return False pre = 0 for i in range(len(s)): try: pre = t.index(s[i], pre) except: return False pre += 1
You can’t perform that action at this time.