Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions .idea/dataSources/268b08ac-a860-48da-aa22-12d69675f3e0.xml

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/itextpdf_5_1_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/itextpdf_5_5_9.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

359 changes: 175 additions & 184 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion SomeTest.iml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="gson-2.2.4.jar">
<CLASSES>
Expand Down Expand Up @@ -324,5 +324,7 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="itextpdf-5.5.9" level="project" />
<orderEntry type="library" name="itextpdf-5.1.0" level="project" />
</component>
</module>
Binary file modified bin/execl/CalCount.class
Binary file not shown.
Binary file modified bin/execl/DisposeData.class
Binary file not shown.
Binary file modified bin/execl/DisposeData2.class
Binary file not shown.
Binary file modified bin/execl/DisposeDataRelease.class
Binary file not shown.
Binary file modified bin/execl/DisposeDataReleaseTwo.class
Binary file not shown.
Binary file modified bin/execl/ExeclParse.class
Binary file not shown.
Binary file modified bin/execl/TimeFormat.class
Binary file not shown.
Binary file added bin/imagesToPDF/JpgToPdf.class
Binary file not shown.
Binary file modified bin/itinterview/stackandqueue/StackGetMin.class
Binary file not shown.
Binary file modified bin/itinterview/stackandqueue/StackSortStack.class
Binary file not shown.
Binary file modified bin/itinterview/stackandqueue/TwoStackQueue.class
Binary file not shown.
Binary file modified bin/leetcode/easy/IntegerToRoman.class
Binary file not shown.
Binary file removed bin/leetcode/easy/ListNode.class
Binary file not shown.
Binary file modified bin/leetcode/easy/MergeTwoLists.class
Binary file not shown.
Binary file modified bin/leetcode/naive/DelLinkedListElement.class
Binary file not shown.
Binary file modified bin/leetcode/naive/IntegerSort.class
Binary file not shown.
Binary file modified bin/leetcode/naive/ListNode.class
Binary file not shown.
84 changes: 84 additions & 0 deletions bin/leetcodeNZ/easy/13_Roman_to_Integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
#
# Symbol Value
# I 1
# V 5
# X 10
# L 50
# C 100
# D 500
# M 1000
# For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.
#
# Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:
#
# I can be placed before V (5) and X (10) to make 4 and 9.
# X can be placed before L (50) and C (100) to make 40 and 90.
# C can be placed before D (500) and M (1000) to make 400 and 900.
# Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.
#
# Example 1:
#
# Input: "III"
# Output: 3

# Example 2:
#
# Input: "IV"
# Output: 4

# Example 3:
#
# Input: "IX"
# Output: 9

# Example 4:
#
# Input: "LVIII"
# Output: 58
# Explanation: L = 50, V= 5, III = 3.

# Example 5:
#
# Input: "MCMXCIV"
# Output: 1994
# Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

class Solution:
def romanToInt(self, s: str) -> int:
rCharMap = {
"M": 1000,
"D": 500,
"C": 100,
"L": 50,
"X": 10,
"V": 5,
"I": 1,
}

index = 0
length = len(s)
result = 0
while index < length:
currentNum = rCharMap[s[index]]
nextIndex = index + 1
if nextIndex < length:
nextNum = rCharMap[s[index + 1]]
else:
nextNum = 0
if nextNum > currentNum:
result -= currentNum
else:
result += currentNum
index += 1
return result


s = Solution()
print("ssss " + str(s.romanToInt("MCMXCIV")))
print(s.romanToInt("LVIII"))
print(s.romanToInt("IX"))
print(s.romanToInt("IV"))



108 changes: 108 additions & 0 deletions bin/leetcodeNZ/easy/14_Longest_Common_Prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Write a function to find the longest common prefix string amongst an array of strings.
#
# If there is no common prefix, return an empty string "".
#
# Example 1:
#
# Input: ["flower","flow","flight"]
# Output: "fl"
# Example 2:
#
# Input: ["dog","racecar","car"]
# Output: ""
# Explanation: There is no common prefix among the input strings.
# Note:
#
# All given inputs are in lowercase letters a-z.


from typing import List


# def getCommonPrefixFromTwoStrs(str_one, str_two) -> str:
# commonPrefix = ""
# str_one_len = len(str_one)
# str_two_len = len(str_two)
#
# index = 0
# if str_one_len > str_two_len:
# loopStr = str_two
# compareStr = str_one
# shorter_len = str_two_len
# else:
# loopStr = str_one
# compareStr = str_two
# shorter_len = str_one_len
#
# cursor = 0
# cursorLen = 1
# while index <= shorter_len:
# cursorStr = loopStr[cursor: cursorLen]
# findIndex = compareStr.find(cursorStr)
# if findIndex >= 0:
# cursorLen += 1
# commonPrefix = cursorStr
# else:
# cursor += cursorLen
# index = cursor + cursorLen
#
# return commonPrefix

def getCommonPrefixFromTwoStrs(str_one, str_two) -> str:
commonPrefix = ""
str_one_len = len(str_one)
str_two_len = len(str_two)

if str_one_len <= 0 or str_two_len <= 0 or str_one[0] != str_two[0]:
print("str_one " + str_one + " str_two " + str_two)
return ""

index = 0
if str_one_len > str_two_len:
loopStr = str_two
compareStr = str_one
shorter_len = str_two_len
else:
loopStr = str_one
compareStr = str_two
shorter_len = str_one_len

cursor = 0
cursorLen = 1
while index <= shorter_len:
cursorStr = loopStr[cursor: cursorLen]
findIndex = compareStr.find(cursorStr)
if findIndex == 0:
cursorLen += 1
commonPrefix = cursorStr
else:
cursor += cursorLen
index = cursor + cursorLen
return commonPrefix

class Solution:

def longestCommonPrefix(self, strs: List[str]) -> str:
listLength = len(strs)
if listLength <= 0:
return ""
if listLength == 1:
return strs[0]
commonPrefix = getCommonPrefixFromTwoStrs(strs[0], strs[1])
print("commonprefix 111 " + commonPrefix + " strs[0] " + strs[0] + " strs[1] " + strs[1])
index = 2
while index < listLength:
itemStr = strs[index]
print("commonprefix 2222 commonPrefix " + commonPrefix + " itemStr " + itemStr)
commonPrefix = getCommonPrefixFromTwoStrs(commonPrefix, itemStr)
print("commonprefix 33333 " + commonPrefix)
index += 1
return commonPrefix



s = Solution()
print(s.longestCommonPrefix(["flower", "flow", "flight"]))
print(s.longestCommonPrefix(["ca", "a"]))
print(s.longestCommonPrefix(["abca","aba","aaab"]))

59 changes: 59 additions & 0 deletions bin/leetcodeNZ/easy/20_Valid_Parentheses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
#
# An input string is valid if:
#
# Open brackets must be closed by the same type of brackets.
# Open brackets must be closed in the correct order.
# Note that an empty string is also considered valid.
#
# Example 1:
#
# Input: "()"
# Output: true
# Example 2:
#
# Input: "()[]{}"
# Output: true
# Example 3:
#
# Input: "(]"
# Output: false
# Example 4:
#
# Input: "([)]"
# Output: false
# Example 5:
#
# Input: "{[]}"
# Output: true


class Solution:
def isValid(self, s: str) -> bool:
while True:
isContainRoundBracket = s.find("()") >= 0
if isContainRoundBracket:
s = s.replace("()", "")

isContainCurlyBracket = s.find("{}") >= 0
if isContainCurlyBracket:
s = s.replace("{}", "")

isContainSquareBracket = s.find("[]") >= 0
if isContainSquareBracket:
s = s.replace("[]", "")

if not isContainRoundBracket and not isContainCurlyBracket and not isContainSquareBracket:
break

if len(s) > 0:
return False
else:
return True

s = Solution()
s.isValid("()")
s.isValid("()[]{}")
s.isValid("(]")
s.isValid("([)]")
s.isValid("{[]}")
66 changes: 66 additions & 0 deletions bin/leetcodeNZ/easy/21_Merge_Two_Sorted_Lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

# Example:

# Input: 1 -> 2 -> 4, 1 -> 3 -> 4
# Output: 1 -> 1 -> 2 -> 3 -> 4 -> 4


# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None


class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
if not l1 and not l2:
return None

if not l1:
return l2

if not l2:
return l1

head = mergedNode = ListNode(0)
while mergedNode is not None:
if l1 is None:
mergedNode.next = l2
return head.next
if l2 is None:
mergedNode.next = l1
return head.next
val1 = l1.val
val2 = l2.val
if val1 < val2:
newNode = ListNode(val1)
l1 = l1.next
else:
newNode = ListNode(val2)
l2 = l2.next
mergedNode.next = newNode
mergedNode = mergedNode.next

node1 = ListNode(4)
node2 = ListNode(2)
node2.next = node1
node3 = ListNode(1)
node3.next = node2

nodeA = ListNode(4)
nodeB = ListNode(3)
nodeB.next = nodeA
nodeC = ListNode(1)
nodeC.next = nodeB

s = Solution()
print("---------------------BEGIN------------ ")
resultNode = s.mergeTwoLists(node3, nodeC)

while resultNode is not None:
print(resultNode.val)
resultNode = resultNode.next

print("---------------------END------------ ")
Loading