Jens Neuhalfen
https://neuhalfen.name/
Recent content on Jens NeuhalfenHugo -- gohugo.ioenSun, 19 Jan 2020 00:00:00 +0100Bouncy GPG 2.2.0 released
https://neuhalfen.name/blog/2020-01-bouncy-gpp-2.2/
Sun, 19 Jan 2020 00:00:00 +0100https://neuhalfen.name/blog/2020-01-bouncy-gpp-2.2/Now with key generation! After more than one year of (slow..) development I am happy to announce the release of bouncy-gpg 2.2.0.
Sample usage For those that do not know bouncy-gpg, it is a java library that greatly simplifies using gpg (rfc4880) encryption in java.
The following two snippets demonstrate how to encrypt and sign a message and later to decrypt the message while checking for the signature.
Please note how bouncy-gpg conveniently wraps an OutputStream so that anything written into it will be encrypted and signed:Testing the compatibility of gpg and bouncy-gpg
https://neuhalfen.name/blog/2020-01-testing-feature-equality/
Sun, 19 Jan 2020 00:00:00 +0100https://neuhalfen.name/blog/2020-01-testing-feature-equality/Driving an external program from java and parsing its output is seldom needed. When it is needed, in often means: no stable API (changes in command output), configuration files, sporadic errors, and orchestrating parallel execution. To test the compatibility with gpg I needed to drive the GnuPG executable.
How to be sure that you implement it correctly? In order to implement key generation for bouncy-gpg I had to make sure that everything I did was compatible with gnupg.LeetCode #746 : Min cost climbing stairs
https://neuhalfen.name/blog/2020-01-leetcode-746-min_cost_climbing_stairs/
Tue, 07 Jan 2020 00:00:00 +0100https://neuhalfen.name/blog/2020-01-leetcode-746-min_cost_climbing_stairs/Description On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).
Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
Example 1:
Input: cost = [10, 15, 20] Output: 15 Explanation: Cheapest is start on cost[1], pay that cost and go to the top.LeetCode #931. Minimum Falling Path Sum
https://neuhalfen.name/blog/2020-01-931-minimum-falling-path-sum/
Tue, 07 Jan 2020 00:00:00 +0100https://neuhalfen.name/blog/2020-01-931-minimum-falling-path-sum/Description Given a square array of integers A, we want the minimum sum of a falling path through A.
A falling path starts at any element in the first row, and chooses one element from each row. The next row's choice must be in a column that is different from the previous row's column by at most one.
Example 1:
Input: [[1,2,3],[4,5,6],[7,8,9]] Output: 12 Explanation: The possible falling paths are:LeetCode #8 : String to Integer (atoi)
https://neuhalfen.name/blog/2019-12-leetcode-008-string-to-integer-atoi/
Fri, 27 Dec 2019 00:00:00 +0100https://neuhalfen.name/blog/2019-12-leetcode-008-string-to-integer-atoi/Preface This problem is quite simple and does not allow for many algorithmic improvements. In fact it would be difficult to come up with a non-optimal (bigger than \(O(n)\)) solution. This makes this problem a good candidate for benchmarking.
I used the following tools:
pytest-benchmark to generate candlestick charts to determine test cases with adverse behavior line_profiler to profile methods line by line CAVE: All tests and benchmarks are run while exporting this page to HTML.LeetCode #10 : Regular Expression Matching
https://neuhalfen.name/blog/2019-12-leetcode-010-regular-expression-matching/
Mon, 16 Dec 2019 00:00:00 +0100https://neuhalfen.name/blog/2019-12-leetcode-010-regular-expression-matching/Description Given an input string (s) and a pattern (p), implement regular expression matching with support for . and *.
. Matches any single character. * Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Note:
s could be empty and contains only lowercase letters a-z. p could be empty and contains only lowercase letters a-z, and characters like .LeetCode #23 : Merge k Sorted Lists
https://neuhalfen.name/blog/2019-12-leetcode-023-merge-k-sorted-lists/
Mon, 16 Dec 2019 00:00:00 +0100https://neuhalfen.name/blog/2019-12-leetcode-023-merge-k-sorted-lists/Description Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4->5->6 (From the problem description)
Test Vectors It is not said in the problem statement, but the implementation bases on the following assumptions
Ordering All lists are ordered ascending and have comparable types. Empty lists Any list can be empty (None) but every node as a non-empty value.LeetCode #1 : Two Sum
https://neuhalfen.name/blog/2019-12-leetcode-001-two-sum/
Sun, 08 Dec 2019 00:00:00 +0100https://neuhalfen.name/blog/2019-12-leetcode-001-two-sum/Description Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. (From the Two-Sum problem description)LeetCode #2: Add Two Numbers
https://neuhalfen.name/blog/2019-12-leetcode-002-add-two-numbers/
Sun, 08 Dec 2019 00:00:00 +0100https://neuhalfen.name/blog/2019-12-leetcode-002-add-two-numbers/Description You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807.LeetCode #3: Longest Substring Without Repeating Characters
https://neuhalfen.name/blog/2019-12-leetcode-003-longest_substring_without_repeating_characters/
Sun, 08 Dec 2019 00:00:00 +0100https://neuhalfen.name/blog/2019-12-leetcode-003-longest_substring_without_repeating_characters/Description Given a string, find the length of the longest substring without repeating characters.
*Example 1*: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. *Example 2*: Input: "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. *Example 3*: Input: "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.