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
@Desolve
Desolve / 0116 Populating Next Right Pointers in Each Node.java
Created Jan 24, 2020
0116 Populating Next Right Pointers in Each Node
View 0116 Populating Next Right Pointers in Each Node.java
/*
// Definition for a Node.
class Node {
public int val;
public Node left;
public Node right;
public Node next;
public Node() {}
@Desolve
Desolve / 0116 Populating Next Right Pointers in Each Node.py
Created Jan 24, 2020
0116 Populating Next Right Pointers in Each Node
View 0116 Populating Next Right Pointers in Each Node.py
"""
# Definition for a Node.
class Node:
def __init__(self, val: int = 0, left: 'Node' = None, right: 'Node' = None, next: 'Node' = None):
self.val = val
self.left = left
self.right = right
self.next = next
"""
class Solution:
View 0091 Decode Ways.java
class Solution {
public int numDecodings(String s) {
if (s.length() == 0) return 0;
int l = s.length();
int dp[] = new int[l+1];
dp[0] = 1; // Empty string
dp[1] = s.charAt(0) != '0' ? 1 : 0;
char prev = '0', curr = s.charAt(0);
for (int i = 2; i <= l; ++i) {
prev = curr;
View 0091 Decode Ways.py
class Solution:
def numDecodings(self, s: str) -> int:
if not s: return 0
l = len(s)
dp = [0] * (l+1)
dp[0], dp[1] = 1, 1 if s[0] != "0" else 0
prev, curr = "0", s[0]
for i in range(2, l + 1):
prev = curr
curr = s[i-1]
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) {
You can’t perform that action at this time.