This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public class Node { | |
char ch; | |
boolean end; | |
HashMap<Character, Node> next = new HashMap<>(); | |
public Node(char ch) { | |
this.ch = ch; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.polythinking.weijingliu.contentview; | |
import android.content.Context; | |
import android.content.res.TypedArray; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.graphics.Rect; | |
import android.graphics.drawable.GradientDrawable; | |
import android.support.annotation.Nullable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.weijingliu.facepileview; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.graphics.Canvas; | |
import android.graphics.Rect; | |
import android.graphics.drawable.BitmapDrawable; | |
import android.graphics.drawable.Drawable; | |
import android.util.AttributeSet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
# @num list of values. | |
# @return list of tuples in [(val, index)...], i.e. [2,1,3] -> [(1,1),(2,0),(3,2)]. | |
def sortedNumbersWithIndex(self, num): | |
tuples = []; | |
for i in range(len(num)): | |
tup = (num[i], i); | |
tuples.append(tup); | |
tuples.sort(key=lambda tup: tup[0]); | |
return tuples; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool isPalindrome(int x) { // 123 | |
if (x < 0) return false; | |
long long num = x; | |
// find the high digit | |
int h = 11; | |
while (h >= 0 && digit(h, num) == 0) h--; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool isInterleave(string s1, string s2, string s3) { | |
if (s1.size() + s2.size() != s3.size()) return false; | |
bool dp[s1.size()+1][s2.size()+1]; | |
for (int len1 = 0 ; len1 <= s1.size() ; len1++) { | |
for (int len2 = 0 ; len2 <= s2.size() ; len2++) { | |
if (len1 == 0 && len2 == 0) { dp[0][0] = true; continue; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
TreeNode* a; | |
TreeNode* b; | |
public: | |
void recoverTree(TreeNode *root) { | |
a = b = 0; | |
if (!root) return; | |
TreeNode* prev = 0; | |
inorder(root, prev); | |
swap(a->val, b->val); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int removeDuplicates(int A[], int n) { | |
int len = 0; | |
for (int i = 0 ; i < n ; ++i) { | |
if (len > 0 && A[len-1] == A[i]) continue; | |
A[len++] = A[i]; | |
} | |
return len; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int removeDuplicates(int A[], int n) { | |
auto C = A; | |
int len = 0; | |
for (int i = 0 ; i < n ; ++i) { | |
if (len >= 2 && C[len-1] == C[len-2] && A[i] == C[len-1]) continue; | |
C[len++] = A[i]; | |
} |
NewerOlder