开发者
编程技术、框架工具、最佳实践
共 7459 篇 · 第 315/373 页
Win16 Memory Management
Show HN: Local-first fast CPU image to text for screenshots, PDFs, webpages
JPEG compression deep dive
submitted by /u/fagnerbrack [link] [留言]
Review: AMD's Radeon RX 9070 GRE is a disappointing way to spend $549
The superior RX 9070 also launched for $549 just over a year ago.
Communication on European Tech Sovereignty, and an EU Open-Source Strategy
Doom on ONNX
submitted by /u/mariuz [link] [留言]
Using local ClickHouse for data processing
submitted by /u/f311a [link] [留言]
Hey guys, it's Ontor. I'm a game developer as well as a mobile app developer, currently exploring places to connect
Majority Element - I
Given an array of size n , find the element that appears more than n/2 times . Example nums = [2,2,1,1,1,2,2] Output: 2 Approach 1: Brute Force For every element, count its occurrences in the entire array. Intuition Check each number and calculate its frequency. If frequency becomes greater than n/2 , return it. Java Code class Solution { public int majorityElement ( int [] nums ) { int n = nums . length ; for ( int i = 0 ; i < n ; i ++) { int count = 0 ; for ( int j = 0 ; j < n ; j ++) { if ( nums [ i ] == nums [ j ]) { count ++; } } if ( count > n / 2 ) { return nums [ i ]; } } return - 1 ; } } Complexity Time: O(n²) Space: O(1) Approach 2: Better Solution (HashMap) Intuition Store the frequency of every element in a HashMap and return the element whose frequency exceeds n/2 . Java Code class Solution { public int majorityElement ( int [] nums ) { HashMap < Integer , Integer > map = new HashMap <>(); for ( int num : nums ) { map . put ( num , map . getOrDefault ( num , 0 ) + 1 ); } for ( int key : map . keySet ()) { if ( map . get ( key ) > nums . length / 2 ) { return key ; } } return - 1 ; } } Complexity Time: O(n) Space: O(n) Approach 3: Optimal Solution (Moore's Voting Algorithm) Key Observation The majority element appears more than half the time. If we keep canceling one majority element with one non-majority element, the majority element will still survive. Think of it as: Same Element -> +1 vote Different Element -> -1 vote Dry Run [2,2,1,1,1,2,2] Element Candidate Count 2 2 1 2 2 2 1 2 1 1 2 0 1 1 1 2 1 0 2 2 1 Final Candidate = 2 Optimal Java Code class Solution { public int majorityElement ( int [] nums ) { int candidate = 0 ; int count = 0 ; for ( int num : nums ) { if ( count == 0 ) { candidate = num ; } if ( num == candidate ) { count ++; } else { count --; } } return candidate ; } } Complexity Time: O(n) Space: O(1) Interview Takeaway Approach Time Space Brute Force O(n²) O(1) HashMap O(n) O(n) Moore's Voting O(n) O(1) The beauty of Moore's Voting A
Google LiteRT-LM Speeds Up Local Inference Up to 2.2x With Gemma 4 Multi-Token Prediction
LiteRT-LM brings native support for Gemma 4 Multi-Token Prediction (MTP) drafters, enabling up to 2.2x faster inference. The framework is expanding beyond Kotlin and C++ adding support for new Swift and a JavaScript APIs. By Sergio De Simone
Krisp Voice Translation API
Real-time speech-to-speech translation built for accuracy Discussion | Link
You Don't Love systemd Timers Enough
submitted by /u/f311a [link] [留言]
Tracing a powerful GNSS interference source over Europe
My Software North Star
submitted by /u/f311a [link] [留言]
Nova Ransomware issues an apology to Eriell Group
A faster bump allocator for rust
submitted by /u/Successful_Bowl2564 [link] [留言]