Skip to content

Instantly share code, notes, and snippets.

Desolve

Block or report user

Report or block Desolve

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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) {
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]
View 0093 Restore IP Addresses.py
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
View 0093 Restore IP Addresses.java
class Solution {
public List<String> restoreIpAddresses(String s) {
List<String> res = new LinkedList<String>();
checkIP(s, res, 0, 0, "");
return res;
}
private void checkIP(String s, List<String> res, int i, int cnt, String cur) {
if (s.length() - i < 4 - cnt) return;
if (cnt == 3) {
if (s.length() - i <= 3) {
@Desolve
Desolve / 0082 Remove Duplicates from Sorted List II.py
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)
@Desolve
Desolve / 0082 Remove Duplicates from Sorted List II.java
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) {
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;
}
}
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:
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;
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.